2011-11-30 43 views
4

我有很多的項目,做工精細垂直滾動佈局。
我想將一個新的線性佈局放置在屏幕的底部,而不是可滾動佈局的一部分。
也就是說,它將坐在獨立於可滾動部分的按鈕上(如adview)。 我只能將它放在scrollView中。
如何將它放在下方,因此始終可見我怎樣才能把新的項目下的滾動型

+0

共享我們的代碼,請 – the100rabh

回答

1

如果您使用垂直LinearLayout來保存可滾動佈局,那麼您可以將adview添加到可滾動佈局下面的LinearLayout,它將出現在屏幕的底部。 (假設您的權重設置正確,並且滾動佈局設置爲WRAP_CONTENT

A RelativeLayout將允許您將adview設置爲與滾動佈局的底部一致,但您仍然需要確保可滾動佈局設置爲WRAP_CONTENT,因此它不會自動佔用整個屏幕。

5

這樣的事情:)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <ScrollView android:id="@+id/scroll_view" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 
     <LinearLayout android:id="@+id/content" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
    </ScrollView> 
    <LinearLayout android:id="@+id/bottom" 
     android:layout_width="fill_parent" 
     android:layout_height="10dip" />   
</LinearLayout> 

您將您的底部添加內容底部的LinearLayout與Android:ID =底部:)

+0

這是行不通的工作。既然你給高度fill_parent的滾動視圖,它將採取整個屏幕,並沒有什麼剩下的滾動視圖後你的LinearLayout。 – Enigma

+0

這將工作... android:layout_weight =「1」修復... – Alioooop

+0

它的工作原理。我認爲這比使用RelativeLayout容易得多。 –

19

使用的RelativeLayout,並組織這樣說:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentTop="true" 
     android:layout_above="@+id/linearLayoutThatDoesNotScroll" > 

     <LinearLayout 
      android:id="@+id/linearLayoutWithLotofContent" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 
     </LinearLayout> 

    </ScrollView> 

    <LinearLayout 
     android:id="@+id/linearLayoutThatDoesNotScroll" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" > 
    </LinearLayout> 

</RelativeLayout> 

技巧是在ScrollView放置中,同時它與屏幕的頂部對齊,並在較低的固定的LinearLayout上方對齊。它只是工作。

+1

**多麼甜蜜!**像魅力一樣工作,謝謝! – user1073511

+0

我們不能使用LinearLayout而不是Relative? –

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

    <Button 
     android:id="@+id/dialogButtonOK" 
     android:layout_width="100px" 
     android:layout_height="wrap_content" 
     android:text=" Ok " 
     android:layout_alignParentBottom="true" 
     android:layout_centerInParent="true" 
     android:background="@drawable/button_style" 
     /> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:id="@+id/scrView" 
     android:layout_above="@id/dialogButtonOK" 
     android:layout_alignParentTop="true" 
     > 
      <HorizontalScrollView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 
         <TableLayout 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:stretchColumns="*" 
         android:id="@+id/main_table" > 
        </TableLayout> 
      </HorizontalScrollView> 
    </ScrollView> 




</RelativeLayout> 

這對我來說

相關問題