开发者

Missing Button Placed after ListView

I have a layout with 3 button at the top in a row and then a ListView followed by a button below the listView. This is my layout.xml file

<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"
    andr开发者_如何学Coid: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>

This will give a result like this

Missing Button Placed after ListView

If i add some values to the ListView then its ok, the button below will be show

Missing Button Placed after ListView

But if the listview becomes larger than the screen size then the button below that will not be visible even after scrolling to the bottom of the listView

Missing Button Placed after ListView

How to solve this issue?? I don't want button to be fixed at the bottom of the screen. I want the button to be show at the end of the ListView only


Change your ListView's height to 0dip. Then change the attribute

android:layout_above="@id/LV_Device" 

to

 android:layout_above="@+id/btn_clearResult"

Finally, modify the last button by removing android:layout_below and add instead android:layout_alignParentBottom="true".


If you got the answer, this is for those who still come in search of the answer for your question. You should be using ListView.addFooterView(yourbutton) to your list. (but don't forget to put this statement before setting adapter for your listview, as stated in the document.)


Shijilal you maybe try this your top button your bottom group button


put your RelativeLayout in a scroll view this way your button will be displayed even after the scroll use this might work

<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>


Initialy no item in the listView.so clear result button at the top. After add some item clear button goes down. But when more items are added clear button goes down & out of screen resolution. I want to know that Initialy when items are added clear button goes down. when clear button reached at bottom then it will not goes down further. you can add more items in the list view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜