2012-02-28 2 views
2

У меня есть проблема, и я пытался прибегая к помощи и поиска других способов, но я не знаю, что искать ...андроид свойства макета XML и позиционирование ...

мой макет выглядит так:

_______________________________________________________ 
|   |  |         | 
|   |  |         | 
| content | button |         | 
|   |  |         | 
|___________|________|__________________________________|             

, но если добавить немного больше это будет выглядеть следующим образом:

_______________________________________________________ 
|       |  |     | 
|       |  |     | 
| content    | button |     | 
|       |  |     | 
|_________________________|________|____________________|             

но когда содержание больше, чем обертку я хочу сделать содержание прокручивать но показать кнопку в конце обертки как это:

_______________________________________________________ 
|            |  | 
|            |  | 
| scrollable content       | button | 
|            |  | 
|______________________________________________|________| 

Так оно не важно, сколько содержание есть, кнопка всегда будет виден и содержание будет горизонтально scollable :)

мой код прямо сейчас что-то вроде этого, но я не знаю, что делать, поэтому я могу получить его, как я хочу:

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/TopBarHeight" > 


     <HorizontalScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="@dimen/TopBarHeight" > 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="@dimen/TopBarHeight" > 
       <LinearLayout 
        android:layout_width="@dimen/TabMaxWidth" 
        android:layout_height="@dimen/TopBarHeight" /> 
       <LinearLayout 
        android:layout_width="@dimen/TabMaxWidth" 
        android:layout_height="@dimen/TopBarHeight" /> 
       <LinearLayout 
        android:layout_width="@dimen/TabMaxWidth" 
        android:layout_height="@dimen/TopBarHeight" /> 
       <LinearLayout 
        android:layout_width="@dimen/TabMaxWidth" 
        android:layout_height="@dimen/TopBarHeight" /> 
       <LinearLayout 
        android:layout_width="@dimen/TabMaxWidth" 
        android:layout_height="@dimen/TopBarHeight" /> 
       <LinearLayout 
        android:layout_width="@dimen/TabMaxWidth" 
        android:layout_height="@dimen/TopBarHeight" /> 
      </LinearLayout>    
     </HorizontalScrollView> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="@dimen/TopBarHeight" > 
      <ImageButton 
       android:layout_width="@dimen/TopBarHeight" 
       android:layout_height="@dimen/TopBarHeight"/> 
     </LinearLayout> 
    </LinearLayout> 
+0

Вы пытались поставить LinearLayout с кнопкой в ​​вашем horizontalscrollview? – maebe

+0

Если я это сделаю, кнопка ul исчезает, когда scrollview заполнен – Alioooop

ответ

0

Я хотел бы предложить топ LinearLayout с общим весом макета 4 и горизонтальной. Затем создайте еще один линейный макет для контента, дайте ему один вес 3 и поместите прокрутку внутрь. Создайте еще один linearlayout с весом 1 и добавьте кнопку к этому макету.

В качестве альтернативы можно использовать релятивирование. Затем вы можете указать, что scrollview выравнивается с родительским слева и справа от кнопки. И кнопка выравнивается с родительским правом и справа от scrollview.

Редакция: Вот пример RelativeLayout, который будет делать то, что вы хотите:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="wrap_content" 
    android:layout_height="48dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" android:layout_toLeftOf="@id/button1"> 
    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </LinearLayout> 
</ScrollView> 
<Button 
    android:id="@+id/button1" 
    android:layout_width="100dp" 
    android:layout_height="48dp" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:text="Button" /> 
</RelativeLayout> 
+0

Я попробовал первый вариант, но не получил его на работу ... – Alioooop

+0

Я добавил RelativeLayout к моему ответу, который будет делать именно то, что вы хотите, я верю. – Tony

+0

Кнопка всегда находится на правом краю экрана по какой-то причине ... например, если scrollview имеет fill_parent ... – Alioooop

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 


    <HorizontalScrollView android:layout_height="@dimen/TopBarHeight" android:layout_width="wrap_content" android:layout_weight="1"> 
     <LinearLayout android:layout_width="wrap_content" 
      android:layout_height="@dimen/TopBarHeight"> 
      <LinearLayout android:layout_width="@dimen/TabMaxWidth" 
       android:layout_height="@dimen/TopBarHeight" /> 
      <LinearLayout android:layout_width="@dimen/TabMaxWidth" 
       android:layout_height="@dimen/TopBarHeight" /> 
      <LinearLayout android:layout_width="@dimen/TabMaxWidth" 
       android:layout_height="@dimen/TopBarHeight" /> 
      <LinearLayout android:layout_width="@dimen/TabMaxWidth" 
       android:layout_height="@dimen/TopBarHeight" /> 
      <LinearLayout android:layout_width="@dimen/TabMaxWidth" 
       android:layout_height="@dimen/TopBarHeight" /> 
      <LinearLayout android:layout_width="@dimen/TabMaxWidth" 
       android:layout_height="@dimen/TopBarHeight" /> 
     </LinearLayout> 
    </HorizontalScrollView> 
    <ImageButton android:layout_width="@dimen/TopBarHeight" android:layout_height="@dimen/TopBarHeight" android:src="@drawable/icon"></ImageButton> 
</LinearLayout> 
+0

Спасибо за код, но с этим кодом кнопка всегда будет на правом краю ... – Alioooop

0

пользователя Компоновка тяжесть для HorizontalScrollView и LinearLayout содержащего ImageButton, как показано ниже.

изменения согласно ниже пунктов

  1. Добавить Android: layout_weight = "1" в HorizontalScrollView

  2. Добавить Android: layout_width = "fill_parent" в HorizontalScrollView

  3. Добавить андроид: layout_weight = "4" во втором Linearlayout, содержащем кнопку изображения

     <HorizontalScrollView 
          android:layout_width="fill_parent" 
          android:layout_height="@dimen/TopBarHeight" 
    android:layout_weight="1"> 
          <LinearLayout 
           android:layout_width="wrap_content" 
           android:layout_height="@dimen/TopBarHeight" > 
           <LinearLayout 
            android:layout_width="@dimen/TabMaxWidth" 
            android:layout_height="@dimen/TopBarHeight" /> 
           <LinearLayout 
            android:layout_width="@dimen/TabMaxWidth" 
            android:layout_height="@dimen/TopBarHeight" /> 
           <LinearLayout 
            android:layout_width="@dimen/TabMaxWidth" 
            android:layout_height="@dimen/TopBarHeight" /> 
           <LinearLayout 
            android:layout_width="@dimen/TabMaxWidth" 
            android:layout_height="@dimen/TopBarHeight" /> 
           <LinearLayout 
            android:layout_width="@dimen/TabMaxWidth" 
            android:layout_height="@dimen/TopBarHeight" /> 
           <LinearLayout 
            android:layout_width="@dimen/TabMaxWidth" 
            android:layout_height="@dimen/TopBarHeight" /> 
          </LinearLayout>    
         </HorizontalScrollView> 
         <LinearLayout 
          android:layout_width="fill_parent" 
          android:layout_height="@dimen/TopBarHeight" 
    android:layout_weight="4"> 
          <ImageButton 
           android:layout_width="@dimen/TopBarHeight" 
           android:layout_height="@dimen/TopBarHeight"/> 
         </LinearLayout> 
        </LinearLayout> 
    
+0

к сожалению это не работало ... – Alioooop

Смежные вопросы