2010-08-31 81 views
0

我是新開發的android開發人員......在創建我的應用程序佈局時,我希望按鈕保持在屏幕的最底部,而滾動視圖位於其上方。我無法做到這一點,我使用滾動視圖的大小爲430dp,以便它的工作原理,但是當我改變屏幕的方向,這不起作用,因爲400dp比屏幕更大。 我該如何讓按鈕停留在屏幕方向的底部? :/Android開發:放置佈局

回答

2

將ScrollView的layout_height設置爲fill_parrent和layout_weight爲1,並將Button的高度設置爲wrap_content。

0

你可以用這個

android:gravity="bottom" 

此去你的元素應該總是推到其容器的底部。

但是,如果您發佈佈局XML,它會更有幫助。

0

下面是一個真實世界的例子,正是你所要求的。 在這個佈局中,我有一個在頂部的標題,一個列表視圖,其下方的所有空間和一個按鈕來清除(取消,失敗,完成)列表視圖的元素,然後在底部我有一個自定義控件顯示一個工具欄。

<?xml version="1.0" encoding="utf-8"?><LinearLayout android:id="@+id/layout" xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical"> 

<LinearLayout android:id="@+id/browsePeerHeader" 
    android:layout_width="fill_parent" android:layout_height="70sp" 
    android:layout_marginBottom="2sp" 
    android:layout_gravity="top" 
    android:background="@drawable/background_barbed_wire" 
    > 


    <ImageButton 
     android:id="@+id/frostwire_sphere" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:src="@drawable/icon" 
     android:layout_gravity="center_vertical" 
     android:layout_margin="3sp" 
     android:background="#00000000"/> 

    <TextView android:id="@+id/browsePeerTitle" android:textSize="30sp" 
     android:text="Downloads" 
     android:textColor="#ffffffff" android:textStyle="bold" 
     android:shadowColor="#ff000000" 
     android:shadowDx="1.0" 
     android:shadowDy="1.0" 
     android:shadowRadius="4.0" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="10sp" 
     android:gravity="left|center_vertical"/> 
</LinearLayout> 


<ListView android:id="@+id/ListViewTransfers" 
    android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
    android:layout_marginTop="2sp" 
      android:layout_marginBottom="2sp" 
    android:layout_weight="1"></ListView> 

<Button android:id="@+id/ButtonClearFinished" margin="2sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
/> 

    <com.frostwire.android.views.FrostWireStatusBar 
    android:id="@+id/FrostWireStatusBar" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" /></LinearLayout> 

下面是截圖 alt text

訣竅基本上是有列表視圖中使用留在包含它的佈局中的所有空間,你甚至不必告訴它FILL_PARENT,只是與android:layout_weight =「1它應該工作。