【发布时间】:2017-10-28 13:24:27
【问题描述】:
我的 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" />
我需要它像这样达到他父母(RelativeLayout)的全高
父布局代码
<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 ipsum,抱歉
Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商采用了一种类型的厨房并将其加扰以制作类型样本书。它不仅经历了五个世纪,而且经历了电子排版的飞跃,基本保持不变。它在 1960 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而流行起来,最近还随着 Aldus PageMaker 等桌面出版软件(包括 Lorem Ipsum 的版本)而普及。
【问题讨论】:
-
有没有试过修改父高度为
match_parent? -
我认为您尝试存档的内容与您在案例中编码的内容不同,recylerview 项目布局具有这样的视图
-
@EasyJoin.net,它起作用了,视图是可见的,但现在它非常大(整个屏幕)所以我的父母应该是 wrap_content
-
等我更新答案
-
@ОлегМісько 我的意思是,如果你有一个父级真实布局,高度为
wrap_content和所有子级'wrap_content',你什么都看不到,因为它是折叠的。现在,由于您的 RelativeLayout 位于其他布局中,因此您还必须在问题中添加它。
标签: android android-layout android-recyclerview