该问题在某种程度上与 API 有关。在 API 9+ 中,单元格看起来很完美,像这样:
但是在 Android 2.3 上它看起来像这样:
我找不到原因。这是我的单元格布局:
<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/