【问题标题】:Why is my button not being displayed?为什么我的按钮不显示?
【发布时间】:2012-02-27 13:07:03
【问题描述】:

我的按钮根据需要设置为大小(wrap_content);它确实有标题,但它是不可见的。它应该就在我的 ListView 下方,我想:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+android:id/listviewContacts"
        android:layout_width="match_parent"
        android:layout_height="300dip"
        android:scrollbars="vertical | horizontal" >
    </ListView>

    <Button
        android:id="@+id/buttonSaveAndBegin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/save_settings_and_begin_responding" />

</LinearLayout>

为什么我的按钮不显示?

【问题讨论】:

    标签: android android-layout android-widget android-xml android-button


    【解决方案1】:

    LinearLayout 的默认方向是水平的。如果您将 android:orientation="vertical" 添加到您的 LinearLayout 中,那么您应该已准备就绪。

    【讨论】:

    • 很好地抓住了方向。
    【解决方案2】:

    像这样在线性布局中添加垂直起点

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

    而且您不需要在列表视图中添加垂直滚动视图属性... Listview 带有默认的垂直滚动视图

    【讨论】:

      【解决方案3】:

      可能是因为300dip高度高于屏幕高度?

      试着把它放低,看看你能不能看到它

      【讨论】:

      • 不,我可以看到 ListView 的轮廓覆盖了大约 2/3 的表单。
      【解决方案4】:

      尝试改变:

      android:layout_height="300dip"
      

      到这里:

      android:layout_height="match_parent"
      

      这很可能是尺寸问题,这将确保您的视图与屏幕的尺寸完全相同。

      【讨论】:

      • 如果我的列表中有无数项怎么办?如果我不指定高度,ListView 不会一直延伸到澳大利亚甚至塔斯马尼亚吗?
      • 它将和父级一样大...关键是这是一个测试..不是解决方案。
      【解决方案5】:

      尝试使用 ListView 页脚添加按钮。

      【讨论】:

        猜你喜欢
        • 2017-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-18
        • 1970-01-01
        • 2021-01-31
        • 1970-01-01
        相关资源
        最近更新 更多