Как получить базовый макет c с помощью MaterialCardView? - PullRequest
0 голосов
/ 09 мая 2020

Я пытаюсь получить следующий макет:

enter image description here

Итак, я написал следующий код:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <!-- Main title -->
    <TextView
        android:id="@+id/MainTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="110dp"
        android:gravity="center"
        android:singleLine="true"
        android:text="Tittle"
        android:textSize="10sp"
        android:textStyle="bold" />

    <!-- Login message -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="40dp"
        android:gravity="center"
        android:singleLine="true"
        android:text="Login as"
        android:textSize="6sp"
        android:textStyle="bold" />

    <!-- Buttons -->
    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="5dp"
        app:cardElevation="2dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_margin="1dp"
            android:layout_height="wrap_content">

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="button 1" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="button 2" />
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>
</RelativeLayout>

Но у меня есть:

enter image description here

Я действительно изо всех сил пытаюсь понять, как достичь этого базового c макета. Что я делаю не так?

1 Ответ

1 голос
/ 09 мая 2020

Попробуйте так

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

    <!-- Main title -->
    <TextView
        android:id="@+id/MainTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:singleLine="true"
        android:text="Tittle"
        android:layout_marginTop="10dp"
        android:textSize="10sp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:singleLine="true"
        android:text="Login as"
        android:layout_above="@id/bottomCardView"
        android:textSize="6sp"
        android:textStyle="bold" />


    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="5dp"
        android:id="@+id/bottomCardView"
        android:layout_alignParentBottom="true"
        app:cardElevation="2dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_margin="10dp"
            android:layout_height="wrap_content">



            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="button 1" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="button 2" />
        </LinearLayout>
    </com.google.android.material.card.MaterialCardView>
</RelativeLayout>

ВЫХОД

enter image description here

...