【发布时间】:2016-09-02 10:44:38
【问题描述】:
当我的视图布局为 wrap_content 时,我的视图在我的 RecyclerView 中消失了。 RecyclerView 是 match_parent 两个方向,并使用一个 LinearLayout 来扩展下面的 xml 文件。以下是 RecyclerView 的每一部分的外观:
这里是它的 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<View
android:id="@+id/scheduleBlockColor"
android:layout_width="15dp"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/scheduleBlockText"
android:background="@color/colorCougarRed" />
<RelativeLayout
android:id="@+id/scheduleBlockText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/scheduleBlockColor"
android:layout_toRightOf="@id/scheduleBlockColor"
android:paddingEnd="0dp"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:paddingStart="5dp">
<TextView
android:id="@+id/scheduleBlockTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="@string/schedule_block_time_default"
android:textSize="16sp" />
<TextView
android:id="@+id/scheduleBlockClassName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/scheduleBlockTime"
android:ellipsize="end"
android:padding="2dp"
android:singleLine="true"
android:text="@string/schedule_block_class_default"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/scheduleBlockRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/scheduleBlockClassName"
android:padding="2dp"
android:text="@string/schedule_block_room_default"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
我的问题是,当 RecyclerView 加载时,如何防止彩色部分消失?如果我将上面的父 RelativeLayout 设置为 match_parent,它可以正常工作。我试过this answer,但没有同样的成功
【问题讨论】:
-
可以给整个RecyclerView截图吗?
-
也发布有问题的屏幕截图
-
@Code-Apprentice 这是颜色失败的屏幕截图。 i.imgur.com/APjn11a.png?1
-
所有的文字肯定仍然像有色块一样,我觉得很奇怪。