簡體   English   中英

按鈕未出現在android appwidget布局中

[英]Button doesn't appear in android appwidget layout

我有這個xml文件作為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>

該按鈕未顯示,我不知道原因。 我測試了match_parent和layout_with,但結果始終相同。

如何解決此問題?

為列表視圖設置固定的高度,例如LinearLayout中的android:layout_height="400dp"

或使用RelativeLayout

或將您的按鈕添加為列表視圖的頁腳。 這樣當您向下滾動時可以看到該按鈕

或將按鈕添加為列表視圖的標題。

使用相對布局,您可以將按鈕放置在頂部或按鈕,相對按鈕可以放置列表視圖。

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

嘗試使用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>

我嘗試看到按鈕,但看不到列表

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM