android - ListView 的自定义单元格与 API9 中的父级宽度不匹配

标签 android android-layout android-listview android-arrayadapter

该问题在某种程度上与 API 有关。在 API 9+ 中,单元格看起来很完美,像这样:

enter image description here

但是在 Android 2.3 上它看起来像这样: enter image description here

我找不到原因。这是我的单元格布局:

<LinearLayout
    android:id="@+id/cell_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="5dp"
    android:background="@drawable/rounded_cell"
    android:orientation="vertical"
    android:padding="5dp" >

    ...content here
</LinearLayout>

列表 fragment 布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/light_gray" >
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#00000000"
        android:paddingTop="5dp" >
    </ListView>
</FrameLayout>

问题肯定出在布局上,因为即使在 Eclipse 的布局编辑器中它也显示错误。如何使其适用于所有 API 9+?

最佳答案

天哪。它始终是该死的FrameLayout。我给你一些建议。不要使用框架布局。即使你认为它适合,也不适合。它会带来很多麻烦。例如,当我将主布局从 FrameLayout 更改为 LinearLayout 时,它工作得很好!

关于android - ListView 的自定义单元格与 API9 中的父级宽度不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16457759/

相关文章:

android - DexException:多个dex文件定义了Lorg/apache/http/params/HttpParamConfig;

java - Android 相机在人像模式下保存图片

android - 如何为 10"以下的选项卡自定义应用程序首选项屏幕(双 Pane 布局)

android - 获取 "android.content.res.resources$notfoundexception"

Android - 如何设置 ListView 的最大大小

android - React native run-android 不更新修改后的代码

android - 支持 :appcompat-v7:26. + 和 firebase-database :16. 0.1 之间的冲突

android - 格局反了?

Android,特殊可绘制对象

Android:如何在此ListView中设置图像?