Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

android - How to make Button overlap CardView at the bottom

I am creating an app that displays announcements, and I want to add a login. I am trying to make this XML design, image. I want the button to OVERLAP the CardView at the bottom and center of it. If it's necessary I'll change the root of the file.

Here is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:background="#fff"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.crescendo.lldm.crescendo.A_Login">

    <RelativeLayout
        android:id="@+id/rl_one_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/v_one_login"
            android:background="@drawable/gradient_background_one"
            android:layout_width="match_parent"
            android:layout_height="300dp" />

        <RelativeLayout
            android:layout_marginTop="90dp"
            android:id="@+id/rl_two_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:textStyle="bold"
                android:id="@+id/tv_one_login"
                android:textSize="32sp"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:text="C R E S C E N D O"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_below="@+id/tv_one_login"
                android:textSize="15sp"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:text="FOR THE USA MONUMENTAL CHOIR"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </RelativeLayout>

    </RelativeLayout>

    <android.support.v7.widget.CardView
        app:cardUseCompatPadding="false"
        app:cardPreventCornerOverlap="false"
        android:id="@+id/cv_one_login"
        app:cardBackgroundColor="#fcfcfc"
        android:layout_marginTop="240dp"
        card_view:cardElevation="10dp"
        app:cardCornerRadius="10dp"
        android:elevation="10dp"
        android:layout_centerHorizontal="true"
        android:layout_width="360dp"
        android:layout_height="280dp">

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

        </RelativeLayout>

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

    <Button
        android:layout_marginTop="197dp"
        android:layout_below="@+id/rl_one_login"
        android:layout_centerHorizontal="true"
        android:elevation="15dp"
        app:backgroundTint="@color/colorPrimary"
        android:layout_width="250dp"
        android:layout_height="50dp" />

</RelativeLayout>

Here is what I get in my XML design, IMAGE2 Hope there is a solution. Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this below layout

<?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:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <View
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="@color/colorAccent" />

    <RelativeLayout
        android:id="@+id/rl_two_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="90dp">

        <TextView
            android:id="@+id/tv_one_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="C R E S C E N D O"
            android:textAlignment="center"
            android:textColor="#ffffff"
            android:textSize="32sp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv_one_login"
            android:text="FOR THE USA MONUMENTAL CHOIR"
            android:textAlignment="center"
            android:textColor="#ffffff"
            android:textSize="15sp" />

    </RelativeLayout>

    <LinearLayout
        android:layout_marginTop="-50dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <android.support.v7.widget.CardView
                android:id="@+id/cv_one_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="240dp"
                android:elevation="10dp"
                app:cardBackgroundColor="#fcfcfc"
                app:cardCornerRadius="10dp"
                app:cardElevation="10dp"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="10dp"
                        android:text="Nilu" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="10dp"
                        android:text="Nilu" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="10dp"
                        android:text="Nilu" />


                </LinearLayout>

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

        <Button
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:layout_below="@id/cv_one_login"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center"
            android:layout_marginTop="-35dp"
            android:elevation="15dp" />


    </LinearLayout>

</RelativeLayout>

OUTPUT

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...