2011-02-14 74 views
6

我有一个布局,在一行顶部有3个按钮,然后是一个ListView,后面跟着一个ListView下面的按钮。 这是我layout.xml文件丢失的按钮放在ListView之后

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

    <Button android:id="@+id/btn_top10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 10"/> 

    <Button android:id="@+id/btn_top100" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 100" 
     android:layout_toRightOf="@id/btn_top10"/> 

    <Button android:id="@+id/btn_showAll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Show All" 
     android:layout_toRightOf="@id/btn_top100"/> 

    <ListView android:id="@+id/LV_Device" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/btn_top10" 
     android:layout_above="@id/LV_Device"/> 

    <Button android:id="@+id/btn_clearResult" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Clear Results" 
     android:layout_below="@id/LV_Device"/> 

</RelativeLayout> 

这将在下面给出这样

enter image description here

结果。如果我一定值添加到ListView那么它的确定,按钮将展示

enter image description here

但是,如果列表视图变得比屏幕尺寸更大然后在下面的按钮,甚至不会滚动到ListView

enter image description here

如何解决这个问题的底部,之后是可见的?我不想让按钮固定在屏幕的底部。我希望该按钮仅显示在ListView的末尾

回答

5

将您的ListView的高度更改为0dip。那么属性

android:layout_above="@id/LV_Device" 

改变

android:layout_above="@+id/btn_clearResult" 

最后,通过去除android:layout_below修改最后一个按钮,并添加代替android:layout_alignParentBottom="true"

+0

Thanks..this works ..但正如我已经说过,我不想要按钮被固定在屏幕的底部。我希望在ListView的末尾看到按钮。怎么做? – Shijilal 2011-02-14 03:39:01

+0

然后,您应该切换到LinearLayout并使用权重。但是你应该知道ListView并不真正支持“wrap_content”高度。当您将其设置为wrap_content时,它总是假设3行的高度。 ListView的要点是能够有效地滚动数以万计(或更多)的项目。 – 2011-02-14 06:34:41

+0

hmm.ohk。因为我无法找到我正在寻找的完美答案..我认为你的建议接近完美..谢谢。但我真的不认为线性布局将能够解决我的问题。 – Shijilal 2011-02-14 16:38:37

0

Shijilal 你也许尝试这个 您的顶部按钮 您的底部组按钮

+0

意味着......组合顶部和底部按钮? – Shijilal 2011-02-14 05:40:42

0

把你的RelativeLayout在滚动视图这样您的按钮甚至会后显示滚动使用这可能工作

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="fill_parent" 
android:paddingTop="10dip" 
android:layout_height="fill_parent" 
android:paddingBottom="10dip"> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:id="@+id/btn_top10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 10" /> 
    <Button 
     android:id="@+id/btn_top100" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TOP 100" 
     android:layout_toRightOf="@id/btn_top10" /> 
    <Button 
     android:id="@+id/btn_showAll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Show All" 
     android:layout_toRightOf="@id/btn_top100" /> 
    <ListView 
     android:id="@+id/LV_Device" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/btn_top10" 
     android:layout_above="@id/LV_Device" /> 
    <Button 
     android:id="@+id/btn_clearResult" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Clear Results" 
     android:layout_below="@id/LV_Device" /> 
</RelativeLayout> 

5

如果你有答案,这是为那些仍然在寻找你的问题的答案的人。你应该使用ListView.addFooterView(yourbutton)到你的清单。 (但是不要忘记在为你的listview设置适配器之前先说明这个声明,如文档中所述)。

0

Initialy没有项目在listView.so顶部清除结果按钮。添加一些项目清除按钮后下降。但是,当更多的项目被添加清除按钮下降&超出屏幕分辨率。我想知道,当项目添加清除按钮时,Initialy会关闭。当清除按钮到达底部时,它不会进一步下降。您可以在列表视图中添加更多项目。