Android 如果我将“回收器视图”子项高度的“简单视图”设置为与父项高度匹配,它将不可见

Android 如果我将“回收器视图”子项高度的“简单视图”设置为与父项高度匹配,它将不可见,android,android-layout,android-recyclerview,Android,Android Layout,Android Recyclerview,我的RecyclerView项目布局左侧有一个简单视图,如下所示 <View android:id="@+id/status_view" android:layout_width="5dp" android:layout_height="match_parent" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:backgr

我的
RecyclerView
项目布局左侧有一个简单视图,如下所示

<View
    android:id="@+id/status_view"
    android:layout_width="5dp"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="@color/pending_color_my_schedule" />

我需要它像这样达到他父母(亲戚)的高度

<View
    android:id="@+id/status_view"
    android:layout_width="5dp"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="@color/pending_color_my_schedule" />

父布局的代码

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/my_schedule_item_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="@dimen/my_schedule_item_margins"
      android:layout_marginRight="@dimen/my_schedule_item_margins"
      android:background="@drawable/shadow_212838"/>

But when I set my `View` to `match_parent's` height it becomes invisible and I can't find a clue why.

If I set it to 150dp or 200dp it works, but I need it to be flexible as the height of parent.

Entire XML file (UPD)

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/my_schedule_item_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginLeft="@dimen/my_schedule_item_margins"
  android:layout_marginRight="@dimen/my_schedule_item_margins"
  android:layout_centerHorizontal="true"
  android:layout_centerVertical="true"
  android:background="@drawable/shadow_212838">

  <TextView
    android:id="@+id/time_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/my_schedule_text_margins"
    android:layout_marginBottom="@dimen/my_schedule_text_margins_small"
    android:layout_marginStart="@dimen/my_schedule_text_margins_start"
    android:layout_marginEnd="@dimen/my_schedule_text_margins"
    android:textColor="@color/black_standart"
    android:textSize="20sp"
    tools:text="Tomorrow: 11:45 - 15:00" />

  <TextView
    android:id="@+id/status_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/my_schedule_text_margins"
    android:layout_marginBottom="@dimen/my_schedule_text_margins_small"
    android:layout_marginEnd="@dimen/my_schedule_text_margins"
    android:layout_alignParentEnd="true"
    android:textSize="12sp"
    tools:text="Pending" />

  <ImageView
    android:id="@+id/status_color_image"
    android:layout_width="@dimen/my_schedule_item_status_size"
    android:layout_height="@dimen/my_schedule_item_status_size"
    android:layout_marginTop="@dimen/my_schedule_status_icon_top_padding"
    android:layout_marginEnd="@dimen/my_schedule_text_margins_small"
    android:layout_toStartOf="@id/status_text"
    android:background="@drawable/pending_circle" />

  <TextView
    android:id="@+id/location_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/my_schedule_text_margins_small"
    android:layout_marginBottom="@dimen/my_schedule_text_margins_small"
    android:layout_marginEnd="@dimen/my_schedule_text_margins_small"
    android:layout_alignStart="@id/time_text"
    android:layout_below="@id/time_text"
    android:drawablePadding="@dimen/my_schedule_text_margins_small"
    android:drawableStart="@drawable/ic_location_grey"
    android:textSize="12sp"
    tools:text="Factory and Co Aeroville" />

  <TextView
    android:id="@+id/function_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/my_schedule_text_margins_small"
    android:layout_marginEnd="@dimen/my_schedule_text_margins_small"
    android:layout_alignStart="@id/time_text"
    android:layout_below="@id/location_text"
    android:paddingBottom="@dimen/my_schedule_text_margins_start"
    android:textSize="14sp"
    tools:text="Function: Manager" />

  <Button
    android:id="@+id/decline_button"
    android:layout_width="@dimen/my_schedule_item_button_width"
    android:layout_height="@dimen/my_schedule_item_button_height"
    android:layout_marginBottom="@dimen/my_schedule_item_buttons_bottom_padding"
    android:layout_alignStart="@id/function_text"
    android:layout_below="@id/function_text"
    android:background="@drawable/blue_transparent_btn_bg"
    android:text="@string/decline"
    android:textColor="@color/clear_blue" />

  <Button
    android:id="@+id/confirm_button"
    android:layout_width="@dimen/my_schedule_item_button_width"
    android:layout_height="@dimen/my_schedule_item_button_height"
    android:layout_marginStart="@dimen/my_schedule_item_buttons_bottom_padding"
    android:layout_below="@id/function_text"
    android:layout_toEndOf="@id/decline_button"
    android:background="@drawable/blue_solid_button_bg"
    android:text="@string/confirm"
    android:textColor="@color/white_standart" />
  <View
    android:id="@+id/status_view"
    android:layout_width="5dp"
    android:layout_height="wrap_content"
    android:background="@color/pending_color_my_schedule" />

</RelativeLayout>

但当我将“视图”设置为“匹配父母的”高度时,它就不可见了,我找不到原因。
如果我将其设置为150dp或200dp,它可以工作,但我需要它作为父级的高度灵活。
整个XML文件(UPD)
这是整个布局,设置为与父项匹配。现在的视图非常大,占据了整个屏幕

如果不添加详细信息,我无法提交,因此我将添加lorem ipsum,抱歉


Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是行业标准的虚拟文本,当时一位不知名的印刷商拿起一个打印工具,将其拼凑成一本打印样本书。它不仅存活了五个世纪,而且还跨越到电子排版,基本上保持不变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表单的发布而流行,最近随着Aldus PageMaker等桌面发布软件的发布而流行,包括Lorem Ipsum版本。

如何将相对人的
布局高度更改为
匹配父项?如果它不能解决您的问题,请将整个xml放在这里好吗?

将相对人的
布局高度更改为
匹配父项如何?如果它不能解决您的问题,您可以将整个xml放在这里吗?

我认为您试图归档的内容与您正在编码的内容不同,在您的情况下,
RecyclerView
项目布局应该是这样的

在代码中做一些更改

1.按如下方式创建您的recycler_items.xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_margin="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fafafa">

        <View
            android:id="@+id/status_view"
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="@color/pending_color_my_schedule" />

        <LinearLayout
            android:padding="16dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!-- Your code here
            Example is given below
            -->
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello World!" />
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/my_schedule_item_layout"
    android:layout_width="match_parent"
    android:background="#eeeeee"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:id="@+id/rvHome"
        android:layout_height="match_parent">
        
    </android.support.v7.widget.RecyclerView>
</RelativeLayout>

我认为您试图归档的内容与您正在编码的内容不同,在您的情况下,
RecyclerView
项目布局应该是这样的

在代码中做一些更改

1.按如下方式创建您的recycler_items.xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_margin="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fafafa">

        <View
            android:id="@+id/status_view"
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="@color/pending_color_my_schedule" />

        <LinearLayout
            android:padding="16dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!-- Your code here
            Example is given below
            -->
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello World!" />
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/my_schedule_item_layout"
    android:layout_width="match_parent"
    android:background="#eeeeee"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:id="@+id/rvHome"
        android:layout_height="match_parent">
        
    </android.support.v7.widget.RecyclerView>
</RelativeLayout>


您是否尝试将父项高度修改为
匹配\u parent
?我认为您尝试归档的内容与您正在编写的内容不同,recylerview项目布局的视图如下所示that@EasyJoin.net,它工作了,视图可见,但现在它非常大(整个屏幕)因此,我的父对象应该是wrap_content,等等,我将更新答案@öММММіааа,我的观点是,如果您有一个父对象的真实布局,在高度
wrap_content
和所有子对象“wrap_content”中,您将看不到任何内容,因为它已折叠。现在,由于您的RelativeLayout位于另一个布局中,您必须在您的问题中添加此内容。您是否尝试将父级高度修改为
匹配\u parent
?我认为您试图存档的内容与您在案例中编写的内容不同,recylerview项目布局的视图如下that@EasyJoin.net,它起作用了,视图是可见的,但现在它非常大(整个屏幕),所以我的父对象应该是wrap_content等等,我将更新答案@öМММіааааааааа。我的观点是,如果您有一个父对象的真实布局,在高度
wrap_content
和所有子对象的“wrap_content”中,您将。现在,因为您的RelativeLayout位于另一个布局中,所以您必须在您的问题中添加它。我已经发布了整个XML文件。您的解决方案使视图可见,但视图会占据整个屏幕。当然。你的布局必须填满整个RecyclerView内容,没错。然后,您可以在RecyclerView标记上控制RecyclerView的大小,因为我已经发布了整个XML文件。您的解决方案使视图可见,但视图会占据整个屏幕。当然。你的布局必须填满整个RecyclerView内容,没错。然后,您可以在RecyclerView标签上控制RecyclerView的大小。尝试按照您的建议将其包装成线性布局-不起作用,不幸的是,我没有';Don’不要用直线布局来包装它。创建回收器视图时,需要传递该权限的布局。因此,将此recyclerview_item.xml添加为布局,它将正常工作,如果您需要在每个recycler视图项中添加内容,请将其添加到给定的位置,否则按我所给的方式保留,并按照您的建议以线性布局将其包装-不起作用,不幸的是@ööСМММіаа39;Don’不要用直线布局来包装它。创建回收器视图时,需要传递该权限的布局。因此,将此recyclerview_item.xml添加为布局,如果您需要在每个recycler视图项中添加内容,请将其添加到给定的位置,否则按我给定的方式保留