将 gridLayout 的高度设置为 wrap_content 后,视图消失 [英] View disappears after setting height of gridLayout to wrap_content
本文介绍了将 gridLayout 的高度设置为 wrap_content 后,视图消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表视图.每行的布局是:
I have a list view. The layout for each row is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:paddingLeft="16dp"
app:columnCount="4">
<View
android:layout_width="3dp"
android:layout_height="wrap_content"
app:layout_row="0"
app:layout_column="1"
app:layout_rowSpan="3"
android:background="@color/background_floating_material_dark"
/>
<ImageView
android:id="@+id/imageView"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_row="0"
app:layout_column="3"
app:layout_gravity="center_vertical"
android:src="@drawable/ic_launcher"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_row="0"
app:layout_column="2"
android:maxWidth="210dp"
android:singleLine="true"
app:layout_gravity="right|center_vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:ellipsize="end"
android:layout_margin="10dp"
android:text="This is title"
/>
<TextView
android:id="@+id/start_time_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="left|center_vertical"
app:layout_row="0"
app:layout_column="0"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:text="۱۱ ق.ظ"
android:paddingRight="5dp"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="right|center_vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/button_material_dark"
android:layout_margin="6dp"
app:layout_row="1"
app:layout_column="2"
android:text="subtitle1" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="25dp"
android:layout_height="25dp"
app:layout_gravity="center_horizontal|center_vertical"
android:src="@drawable/ic_supervisor_account_black_24dp"
app:layout_row="1"
app:layout_column="3"/>
</android.support.v7.widget.GridLayout>
我想要的是这个:
但是当我将 GridLayout 高度更改为 wrap_content 时,黑线消失了.如果将高度设置为恒定值,我可以看到黑线:
But when I change the GridLayout height to wrap_content, the black line disappears. I can see the black line if I set the height to a constant value:
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="150dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
app:columnCount="4">
但我不想每行都具有相同的高度.有什么问题?
But I don't want to have a same height for each row. What is the problem?
推荐答案
您应该将视图(黑线)的layout_height
更改为 0 dp 并使用 layout_gravity
为 <代码>填充代码>.
You should change the layout_height
of view (black line) to 0 dp and use layout_gravity
to fill
.
<View
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_row="0"
app:layout_column="1"
app:layout_rowSpan="3"
app:layout_gravity="fill"
android:background="@color/dim_foreground_disabled_material_dark"
/>
这篇关于将 gridLayout 的高度设置为 wrap_content 后,视图消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文