Сделать андроид макет дочерним по ширине, чем родитель - PullRequest
0 голосов
/ 15 октября 2018

Мой код:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp">

    <View
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:background="#00ff00"/>
</android.support.v7.widget.CardView>

Мой вывод enter image description here Я хочу, чтобы зеленый вид соответствовал всей ширине родительского экрана.Это возможно?Я хочу использовать вид карты как родительский, поскольку он будет иметь повышение прав.

1 Ответ

0 голосов
/ 15 октября 2018

Вот ваше решение ...

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        />
    <View
        android:id="@+id/fab"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_centerVertical="true"
        android:background="#00ff00"
        />
</RelativeLayout>
...