Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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 当父项为换行内容时匹配父项?_Android_Xml_Material Design - Fatal编程技术网

Android 当父项为换行内容时匹配父项?

Android 当父项为换行内容时匹配父项?,android,xml,material-design,Android,Xml,Material Design,我对安卓系统的开发相当陌生。我正在尝试添加一个彩色矩形来填充cardwiew的高度。这是我的XML <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center_horizontal"

我对安卓系统的开发相当陌生。我正在尝试添加一个彩色矩形来填充
cardwiew
的高度。这是我的XML

<android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <View android:id="@+id/color_bar"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:background="#673AB7" />

             ...

        </RelativeLayout>
    </android.support.v7.widget.CardView>

...
但是,该条不会出现在卡片中。它似乎没有获得
match\u parent
的卡片高度(如果我硬编码dp中的高度,它会显示)。这是因为卡片的高度设置为
wrap\u content
还是完全不同?我在API 16上

编辑:以下是我想要实现的目标:


然而,这是用硬编码的dp值完成的,不能扩展到设备。我正在尝试使此条适应卡的大小。

可能嵌套在
线性布局中
并使用
权重

<android.support.v7.widget.CarView
    ...>

    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="horizontal">
         <View
             android:layout_width="0dp"
             android:layout_height="match_parent"
             android:layout_weight="10"
             android:background="#67BA37"/>
         <RelativeLayout
             android:layout_width="0dp"
             android:layout_height="match_parent"
             android:layout_weight="100"
             ...>
             ...
          </RelativeLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

...

不是很平坦,但似乎有效

不能指定冲突的布局参数。如果子项有匹配父项,父项有换行内容,则有一个循环。@Zielony我明白了。这是有道理的。我该如何以另一种方式实现我的目标?我想你可以将颜色条的高度设置为dp(比如50dp),将
RelativeLayout的高度设置为
wrap\u content
。它应该work@bipin问题是,我也有文本(因此是wrap_内容),并且该栏无法缩放以适应,这意味着在许多设备上,该栏要么太长,要么太短。如果您希望视图(该栏)靠近CardView,只需交换容器:RelativeLayout将包含CardView和View,一个挨着另一个。