Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将gridLayout的高度设置为包裹内容后,视图将消失_Android_Android Layout_Layoutparams_Android Gridlayout - Fatal编程技术网

Android 将gridLayout的高度设置为包裹内容后,视图将消失

Android 将gridLayout的高度设置为包裹内容后,视图将消失,android,android-layout,layoutparams,android-gridlayout,Android,Android Layout,Layoutparams,Android Gridlayout,我有一个列表视图。每行的布局为: <?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"

我有一个列表视图。每行的布局为:

<?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_内容时,黑线消失了。如果我将高度设置为常量,我可以看到黑线:

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


但我不想每行都有相同的高度。问题是什么?

您应该将视图(黑线)的
layout\u height
更改为0 dp,并使用
layout\u gravity
填充

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