如何使按钮在底部与 CardView 重叠 [英] How to make Button overlap CardView at the bottom

查看:39
本文介绍了如何使按钮在底部与 CardView 重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个显示公告的应用程序,我想添加一个登录名.我正在尝试制作这个 XML 设计,.我希望按钮在底部和中心重叠 CardView.如果有必要,我会更改文件的根目录.

这是我的 XML 代码:

<相对布局android:id="@+id/rl_one_login"android:layout_width="match_parent"android:layout_height="wrap_content"><查看android:id="@+id/v_one_login"android:background="@drawable/gradient_background_one"android:layout_width="match_parent"android:layout_height="300dp"/><相对布局android:layout_marginTop="90dp"android:id="@+id/rl_two_login"android:layout_width="match_parent"android:layout_height="wrap_content"><文本视图android:textStyle="粗体"android:id="@+id/tv_one_login"android:textSize="32sp"机器人:文本对齐=中心"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"/><文本视图android:layout_below="@+id/tv_one_login"android:textSize="15sp"机器人:文本对齐=中心"android:textColor="@color/colorWhite"android:text="为了美国纪念合唱团"android:layout_width="match_parent"android:layout_height="wrap_content"/></RelativeLayout></RelativeLayout><android.support.v7.widget.CardView应用程序:cardUseCompatPadding="false"应用程序:cardPreventCornerOverlap="false"android:id="@+id/cv_one_login"应用程序:cardBackgroundColor="#fcfcfc"android:layout_marginTop="240dp"card_view:cardElevation="10dp"应用程序:cardCornerRadius="10dp"机器人:海拔=10dp"机器人:layout_centerHorizo​​ntal="true"android:layout_width="360dp"android:layout_height="280dp"><相对布局android:layout_width="match_parent"android:layout_height="match_parent"></RelativeLayout></android.support.v7.widget.CardView><按钮android:layout_marginTop="197dp"android:layout_below="@+id/rl_one_login"机器人:layout_centerHorizo​​ntal="true"机器人:海拔=15dp"app:backgroundTint="@color/colorPrimary"android:layout_width="250dp"android:layout_height="50dp"/></RelativeLayout>

这是我在 XML 设计中得到的内容,

I am creating an app that displays announcements, and I want to add a login. I am trying to make this XML design, . 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!

解决方案

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

这篇关于如何使按钮在底部与 CardView 重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆