2010-08-31 62 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它应该工作。