2012-02-28 91 views
2

我有一個問題,我已經試着用搜索引擎和其他方式尋找,但我不知道該怎麼尋找...Android的佈局XML屬性和定位...

我的佈局是這樣的:

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

但如果我補充一點它看起來就像這樣:

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

但當含量低於包裝大我要讓內容滾動,但顯示出在包裝結束按鈕喜歡這樣的:

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

所以它不會不管有多少內容有,該按鈕將始終可見,內容將是horizo​​ntaly 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與您的按鈕放在horizo​​ntalscrollview中? – maebe 2012-02-28 11:31:58

+0

如果我這樣做,按鈕VILL disapear時滾動視圖充滿 – Alioooop 2012-02-28 11:44:40

回答

0

我會建議一個頂部LinearLayout總佈局權重4和水平。 然後爲內容創建另一個線性佈局,給那個3的權重並在裏面放置一個滾動視圖。創建權重爲1的另一個線性佈局,並將該按鈕添加到該佈局。

或者使用relativelayout。然後,您可以指定將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 2012-02-28 11:50:36

+0

我添加了一個RelativeLayout的,以我的回答會做正是你想要的,我相信。 – Tony 2012-02-28 13:57:50

+0

由於某種原因,該按鈕始終位於屏幕的右邊緣...如果滾動視圖具有fill_parent ... – Alioooop 2012-02-28 15:25:33

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 2012-02-28 11:47:08

0

用戶佈局重力Horizo​​ntalScrollView和包含的LinearLayout作爲的ImageButton以下。

變化是按以下分

  1. 添加機器人:layout_weight = 「1」 在Horizo​​ntalScrollView

  2. 添加機器人:在Horizo​​ntalScrollView

    layout_width = 「FILL_PARENT」
  3. 添加機器人: layout_weight = 「4」 在第二的LinearLayout含有的ImageButton

     <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

可悲的是,這沒有工作eather ... – Alioooop 2012-02-28 11:56:29