【发布时间】:2016-06-12 13:02:54
【问题描述】:
我在DialogFragment 中有一个非常简单的RecyclerView
单行项目应该显示图像、名字和姓氏以及一些数字。它们在 layout_weight 的帮助下进行布局,以平均共享可用空间。
由于某种原因,有些项目似乎随机计算 layout_weight 错误。
请注意,在编辑器预览中,将有问题的项目滚动出视图后,问题已修复,布局恢复正常。
正如您在图片中看到的,在第一项(并不总是(只是)第一项)中,图片占用了太多空间。
我的布局如下;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/dodger_blue"
android:orientation="horizontal"
android:padding="8dp">
<ImageView
android:id="@+id/iv_face"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/et_first_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:textStyle="bold"/>
<TextView
android:id="@+id/et_surname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMediumInverse"/>
</LinearLayout>
<TextView
android:id="@+id/et_id"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMediumInverse"/>
<TextView
android:id="@+id/et_place"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:gravity="center|end"
android:textAppearance="?android:attr/textAppearanceLargeInverse"/>
</LinearLayout>
还有我的适配器; https://gist.github.com/StefanDeBruijn/f032eac6619ac1b8420e352b883ea4dd
【问题讨论】:
-
您是否在您的
Adapter中的inflate()调用中传递父ViewGroup? -
是的,我的整个适配器都添加了要点
标签: android android-recyclerview android-layout-weight