Question

I have this xml file as a layout of an appwidget:

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

    <!-- ListView to be shown on widget -->
    <ListView
        android:id="@+id/listViewWidget"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/refresh_appwidget"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="refresh"
 />

</LinearLayout>

The button is not displayed, and I don't know the cause. I tested layout_with match_parent but always the same result.

How can I fix this issue?

Était-ce utile?

La solution

Set a fixed height for the listview for example android:layout_height="400dp" in LinearLayout.

Or use a RelativeLayout

Or add your button as a footer to listview. So you can see the button when you scroll down

Or add your button as a header to listview.

With Relative layout you can place the button at the top or button and relative tot eh button you can place your listview.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="@android:color/black"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Button" />

    <ListView
        android:id="@+id/listView1"
        android:layout_above="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" >

    </ListView>

</RelativeLayout>

Autres conseils

Try with 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="wrap_content"
    android:orientation="vertical"
    android:background="@android:color/black" >

<!--     ListView to be shown on widget -->
    <ListView
        android:id="@+id/listViewWidget"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/refresh_appwidget"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="refresh"

 />

</RelativeLayout>

I try and see the Button but dont see the List

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top