【问题标题】:ListView and layout. Why ListView overlaps everything?ListView 和布局。为什么 ListView 重叠一切?
【发布时间】:2014-05-04 18:58:29
【问题描述】:

这是经过编辑的版本! 我是编写 Android 应用程序的新手,我认为这真的很难,不是 java 而是 ui。我正在尝试获取类别列表。它们可以是 listView 内带有 textview 的复选框或其他东西。想法是用户可以只按下框/标签/复选框/按钮,多选。我最终选择了复选框,因为它感觉是最简单的方法,有什么建议可以为最终用户获得最简单的解决方案吗?用户可以添加自己的类别,所以最后一行是用户可以添加新类别的按钮。

问题

我怎样才能获得这些类别复选框不与设置栏、按钮等重叠的布局? 部分解决:我将 framelayout 更改为 LinearLayout,并将启动图像从 imageView 更改为 android:background 到 layout。现在我可以看到所有内容,但顺序不对。如果我将 topframe 移到顶部(它应该在的位置),我会收到如下错误消息:

错误: java.lang.ClassCastException: android.widget.LinearLayout 不能转换为 android.widget.Button

ACTIVITY.xml

<LinearLayout
    android:id="@+id/buttonContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:orientation="vertical" >

    <Button
        android:id="@+id/category"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/white_button"
        android:minHeight="40dp"
        android:text="@string/category"
        android:textColor="#ffffff"
        android:textStyle="bold" />

    <Button
        android:id="@+id/tak"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/white_button"
        android:minHeight="40dp"
        android:text="@string/take"
        android:textColor="#ffffff"
        android:textStyle="bold" />

    <Button
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/white_button"
        android:minHeight="40dp"
        android:text="@string/list"
        android:textColor="#ffffff"
        android:textStyle="bold" />
</LinearLayout>

<LinearLayout
    android:id="@+id/topframe"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#99a8b3b9" >

    <Button
        android:id="@+id/settings_button"
        android:layout_width="43dp"
        android:layout_height="37dp"
        android:background="@drawable/ic_sysbar_quicksettings" />

    <TextView
        android:id="@+id/top_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:text="@string/no_category_text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFFFF" />
</LinearLayout>

【问题讨论】:

  • 布局中的父 ViewGroup 是什么?
  • 我刚来,我认为这是问题所在。 schemas.android.com/apk/res/android"

标签: android android-layout android-listview


【解决方案1】:

不要使用 FrameLayout 来构建这样的 UI。 FrameLayout 将所有子项放在左上角,这就是您的视图重叠的原因。我所看到的具有垂直方向的 LinearLayout 应该可以完成这项工作。

例如使用这样的一个:

<LinearLayout
    ...
    android:orientation="vertical">

    ...

    <LinearLayout
        android:id="@+id/topframe"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#99a8b3b9" >

        <Button
            android:id="@+id/settings_button"
            android:layout_width="43dp"
            android:layout_height="37dp"
            android:background="@drawable/ic_sysbar_quicksettings" />

        <TextView
            android:id="@+id/top_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:text="@string/no_category_text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF" />
    </LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="377dp" >
    </ListView>

    ...

</LinearLayout>

【讨论】:

  • 我也试试这个。我认为那些与背景图像重叠的按钮可能有问题,我猜是这样......
  • 我试过这个,现在我只能看到一个带有图像的启动画面,没有复选框,没有按钮,只有启动图像。
  • 编辑:我取消了 imageview 并在 linearLayout 中使用了 android:background="@drawable/splash">。现在这是可行的,但按钮是最顶部的,然后是 topframe,然后是复选框。这很有趣:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多