如果我设置回收站查看子项目高度的简单视图match_parent它变得不可见

问题描述:

我有我的RecyclerView项目布局的左边,看起来像这样如果我设置回收站查看子项目高度的简单视图match_parent它变得不可见

<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的)这样

enter image description here

父布局的代码

<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> 

这是整个布局,它被设置为match_parent。现在这个视图非常大,占据了整个屏幕。

我不能没有添加信息提交,所以我将添加Lorem存有,对不起

Lorem存有简直是印刷排版行业的虚拟文本。 Lorem Ipsum自从16世纪以来一直是业界标准的虚拟文本,当时一台未知的打印机采用了一种类型的厨房,并将其制作成样本书。它不仅存活了五个世纪,而且还实现了电子排版的飞跃,基本保持不变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset工作表的发布以及最近使用包括版本的Lorem Ipsum在内的Aldus PageMaker等桌面出版软件而得到了推广。

+0

您是否尝试将父高度修改为'match_pare nt'? –

+0

我觉得你要存档的东西不同于你正在编码的东西,recylerview项目布局有一个类似于 –

+0

@EasyJoin的视图。净,它的工作,视图是可见的,但现在它是非常大的(整个屏幕),所以我的父母应该是wrap_content –

怎么样将亲戚的layout_height更改为match_parent?如果它不能解决你的问题,你可以把整个xml放在这里吗?

+0

我已经发布了整个XML文件。您的解决方案使视图可见,但视图占据整个屏幕。 –

+0

当然。您的布局必须填写整个RecyclerView内容,这是正确的。然后,您可以在RecyclerView标记上控制RecyclerView的大小 –

我认为你正试图存档比你的编码是什么不同的东西,你的情况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> 

2.Change你main_layout.xml如下

<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_item.xmlheight已设置为100dp,这仅用于演示目的。 如果你想使视图wrap_content可调节高度recyclerview_item.xml


所有height属性更改为wrap_content(包括父母和子女)添加下面的依赖

implementation 'com.android.support:cardview-v7:27.0.0' //Check your version 
implementation 'com.android.support:recyclerview-v7:27.0.0' 
+0

试图按照您的建议将其包装在LinearLayout中 - 不起作用,不幸的是, –

+0

@ОлегМісько我没有将'包装到LinearLayout中。当您创建回收站视图时,您需要为该权利传递布局。因此,将这个rec​​yclerview_item.xml作为该布局添加它可以正常工作 –

+0

@ОлегМісько如果您需要在每个回收站视图项目中添加一些内容,请在给定的位置添加该内容,否则请按照我的指示继续 –