【问题标题】:How to make Button overlap CardView at the bottom如何使Button在底部重叠CardView
【发布时间】:2017-12-11 01:36:24
【问题描述】:

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

这是我的 XML 代码:

<?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>

这是我在 XML 设计中得到的,IMAGE2 希望有一个解决方案。谢谢!

【问题讨论】:

  • 您可以使用框架布局或带有负上边距的按钮底视图的相对布局。但请记住,在棒棒糖下方,您必须提供底部按钮视图高度而不是卡片视图

标签: android android-layout android-xml android-cardview


【解决方案1】:

试试下面的布局

<?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>

输出

【讨论】:

    【解决方案2】:

    您可以使用Constraint Layout library 和设计选项卡轻松完成此操作。

    Sample photo

    这是代码,但我在设计选项卡中完成了大部分操作。

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v7.widget.CardView
            android:id="@+id/credentials_card"
            android:layout_width="150dp"
            android:layout_height="250dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.281">
    
            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <EditText
                    android:id="@+id/username_field"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="48dp"
                    android:hint="Username"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.511"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
    
                <EditText
                    android:id="@+id/passworld_field"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    android:hint="Password"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/username_field" />
    
            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.CardView>
    
        <Button
            android:id="@+id/login_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:text="Login!"
            app:layout_constraintBottom_toBottomOf="@+id/credentials_card"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/credentials_card" />
    
    </android.support.constraint.ConstraintLayout>
    

    【讨论】:

    • 朋友,这在使用约束布局时最有效。这正是我想要的。
    • 但是我无法添加这个带有高度的按钮。
    【解决方案3】:

    使用 ConstraintLayout 可以解决这个问题:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 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"
        android:background="@android:color/white">
    
        <View
            android:id="@+id/view_blank"
            android:layout_width="match_parent"
            android:layout_height="260dp"
            android:background="@color/colorPrimary"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"/>
    
        <ImageView
            android:id="@+id/image_logo"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:layout_marginTop="80dp"
            android:src="@drawable/ic_action_facebook"
            android:tint="@android:color/white"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"/>
    
    
        <android.support.constraint.ConstraintLayout
            android:id="@+id/credentials_card"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="20dp"
            android:padding="@dimen/spacing_mlarge"
            app:layout_constraintTop_toBottomOf="@+id/image_logo"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent">
    
    
            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/spacing_medium"
                android:visibility="visible"
                app:cardUseCompatPadding="true"
                app:cardCornerRadius="6dp"
                app:cardElevation="5dp"
                tools:ignore="MissingConstraints">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="@dimen/spacing_xmlarge">
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginBottom="25dp"
                        android:text="SIGN IN"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                        android:textColor="@color/colorAccent"
                        android:textStyle="bold" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="USERNAME"
                        android:textAlignment="center"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                        android:textColor="@color/colorPrimary" />
    
                    <android.support.design.widget.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="text"
                        android:maxLength="50"
                        android:maxLines="1"
                        android:singleLine="true"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                        android:textColor="@color/colorPrimary"
                        android:textStyle="bold"
                        android:theme="@style/EditText.Grey" />
    
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:text="PASSWORD"
                        android:textAlignment="center"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                        android:textColor="@color/colorPrimary" />
    
                    <android.support.design.widget.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textPassword"
                        android:maxLength="50"
                        android:maxLines="1"
                        android:singleLine="true"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                        android:textColor="@color/colorPrimary"
                        android:textStyle="bold"
                        android:theme="@style/EditText.Grey" />
    
    
                </LinearLayout>
    
            </android.support.v7.widget.CardView>
    
        </android.support.constraint.ConstraintLayout>
    
        <Button
            android:id="@+id/sign_up"
            android:layout_width="match_parent"
            android:layout_height="57dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:background="@drawable/btn_rounded_primary"
            android:text="S I G N  I N"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/credentials_card"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"/>
    
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:layout_marginTop="20dp"
            android:text="FORGET PASSWORD"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
            android:textColor="@color/grey_40"
            android:textStyle="bold"
            app:layout_constraintTop_toBottomOf="@+id/sign_up"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"/>
    
    
    </android.support.constraint.ConstraintLayout>
    

    这里是btn_rounded_primary:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true">
    
            <layer-list>
                <item android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp">
                    <shape android:shape="rectangle">
                        <corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:radius="60dp" android:topLeftRadius="30dp" android:topRightRadius="30dp" />
                        <solid android:color="@color/colorPrimaryDark" />
                        <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp" />
                        <size android:width="110dp" android:height="40dp" />
                    </shape>
                </item>
            </layer-list>
    
        </item>
        <item android:state_focused="true">
    
            <layer-list>
                <item android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp">
                    <shape android:shape="rectangle">
                        <corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:radius="60dp" android:topLeftRadius="30dp" android:topRightRadius="30dp" />
                        <solid android:color="@color/colorPrimaryDark" />
                        <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp" />
                        <size android:width="110dp" android:height="40dp" />
                    </shape>
                </item>
            </layer-list>
    
        </item>
    
        <item>
    
            <layer-list>
                <item android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp">
                    <shape android:shape="rectangle">
                        <corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:radius="60dp" android:topLeftRadius="30dp" android:topRightRadius="30dp" />
                        <solid android:color="@color/colorPrimary" />
                        <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp" />
                        <size android:width="110dp" android:height="40dp" />
                    </shape>
                </item>
            </layer-list>
    
        </item>
    </selector>
    

    这里是dimens.xml:

    <!--genaral spacing-->
    <dimen name="spacing_xsmall">2dp</dimen>
    <dimen name="spacing_small">3dp</dimen>
    <dimen name="spacing_medium">5dp</dimen>
    <dimen name="spacing_xmedium">7dp</dimen>
    <dimen name="spacing_middle">10dp</dimen>
    <dimen name="spacing_large">15dp</dimen>
    <dimen name="spacing_smlarge">18dp</dimen>
    <dimen name="spacing_mlarge">20dp</dimen>
    <dimen name="spacing_mxlarge">25dp</dimen>
    <dimen name="spacing_xlarge">35dp</dimen>
    <dimen name="spacing_xmlarge">40dp</dimen>
    <dimen name="spacing_xxlarge">50dp</dimen>
    <dimen name="spacing_xxxlarge">55dp</dimen>
    <dimen name="appbar_padding_top">8dp</dimen>
    

    colors.xml

    <color name="grey_3">#f7f7f7</color>
    <color name="grey_5">#f2f2f2</color>
    <color name="grey_10">#e6e6e6</color>
    <color name="grey_20">#cccccc</color>
    <color name="grey_40">#999999</color>
    <color name="grey_60">#666666</color>
    <color name="grey_80">#37474F</color>
    <color name="grey_90">#263238</color>
    

    使用 ConstraintLayout 输出:

    【讨论】:

    • 你不认为你错过了按钮的顶部约束吗?或者还有什么可以解决的吗?
    • HI@Rahul,如果您想使用toolbar,请使用toolbar 代码。我在没有使用toolbar 的情况下提交了这个解决方案。这也是全屏页面的解决方案。
    【解决方案4】:

    试试这个

    输出

    <?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/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">
    
    <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:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="#0000FF" />
    
        <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>
    
    </RelativeLayout>
    
    <LinearLayout
        android:id="@+id/lin_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="150dp"
        android:visibility="visible">
    
        <android.support.v7.widget.CardView
            android:id="@+id/cv_one_login"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            android:layout_centerHorizontal="true"
            android:layout_margin="15dp"
            android:elevation="10dp"
            app:cardBackgroundColor="#fcfcfc"
            app:cardCornerRadius="10dp"
            app:cardPreventCornerOverlap="false"
            app:cardUseCompatPadding="false"
            card_view:cardElevation="10dp">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
            </RelativeLayout>
    
        </android.support.v7.widget.CardView>
    
    </LinearLayout>
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="37dp"
        android:elevation="15dp"
        android:gravity="center">
    
        <Button
            android:id="@+id/button"
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:background="@drawable/custom_circle"
            android:text="Login"
            android:textAllCaps="false"
            android:textColor="#fff" />
    </LinearLayout>
    

    custom_circle.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <corners android:radius="50dp" />
        <solid android:color="@color/colorPrimary" />
    
    </shape>
    

    【讨论】:

      【解决方案5】:

      我已经阅读了这里的每一个答案,我已经放弃了每一个因为以下动机

      1. 我不想使用负边距,不建议这样做。
      2. 我不想用户LinearLayout
      3. 其他答案对我不起作用

      所以,我终于解决了我的问题,只需将Button 包装在另一个ConstraintLayout 中,并在ConstraintLayout 中添加一些elevation

      这是我的结果

      这是一个工作示例

      <?xml version="1.0" encoding="utf-8"?>
      <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
          <androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent">
      
              <com.google.android.material.card.MaterialCardView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginStart="16dp"
                  android:layout_marginTop="16dp"
                  android:layout_marginEnd="16dp"
                  android:layout_marginBottom="28dp"
                  app:layout_constraintBottom_toBottomOf="parent"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent">
      
                  <androidx.constraintlayout.widget.ConstraintLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:paddingBottom="28dp">
      
                      <ImageView
                          android:id="@+id/user_avatar"
                          android:layout_width="0dp"
                          android:layout_height="92dp"
                          android:layout_marginTop="16dp"
                          android:layout_marginBottom="16dp"
                          android:src="@drawable/sample_food_1"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toTopOf="parent"
                          app:layout_constraintWidth_percent="0.4" />
      
                      <TextView
                          android:id="@+id/user_name"
                          style="?attr/textAppearanceHeadline4"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_marginTop="16dp"
                          android:gravity="center"
                          android:maxLines="2"
                          android:text="Lorem ipsum lorem ipsum"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toBottomOf="@id/user_avatar" />
      
                      <TextView
                          android:id="@+id/user_description"
                          style="?attr/textAppearanceSubtitle1"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center"
                          android:maxLines="2"
                          android:text="Lorem ipsum lorem ipsum"
                          app:layout_constraintEnd_toEndOf="parent"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toBottomOf="@id/user_name" />
      
                  </androidx.constraintlayout.widget.ConstraintLayout>
      
              </com.google.android.material.card.MaterialCardView>
      
              <androidx.constraintlayout.widget.ConstraintLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:elevation="10dp"
                  android:paddingStart="16dp"
                  android:paddingEnd="16dp"
                  app:layout_constraintBottom_toBottomOf="parent"
                  app:layout_constraintStart_toStartOf="parent">
      
                  <Button
                      android:id="@+id/button_edit_profile"
                      android:layout_width="0dp"
                      android:layout_height="56dp"
                      android:layout_marginStart="16dp"
                      android:layout_marginEnd="8dp"
                      android:text="Some Button!!"
                      app:layout_constraintEnd_toStartOf="@id/button_saved_videos"
                      app:layout_constraintStart_toStartOf="parent"
                      app:layout_constraintTop_toTopOf="parent" />
      
                  <Button
                      android:id="@+id/button_saved_videos"
                      android:layout_width="0dp"
                      android:layout_height="56dp"
                      android:layout_marginStart="8dp"
                      android:layout_marginEnd="16dp"
                      android:text="Some Button!!"
                      app:layout_constraintEnd_toEndOf="parent"
                      app:layout_constraintStart_toEndOf="@id/button_edit_profile"
                      app:layout_constraintTop_toTopOf="parent" />
      
              </androidx.constraintlayout.widget.ConstraintLayout>
      
          </androidx.constraintlayout.widget.ConstraintLayout>
      
      </androidx.constraintlayout.widget.ConstraintLayout>
      

      【讨论】:

        【解决方案6】:

        使用下面的代码根据按钮高度调整margintop。我已将其设置为 -25dp,因为它是 50dp 高度

          <?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_below="@id/cv_one_login"
                    android:layout_centerHorizontal="true"
                    android:elevation="15dp"
                    android:layout_marginTop="-25dp"
                    app:backgroundTint="@color/colorPrimary"
                    android:layout_width="250dp"
                    android:layout_height="50dp" />
        
            </RelativeLayout>
        

        【讨论】:

          【解决方案7】:
          <?xml version="1.0" encoding="utf-8"?>
          <android.support.design.widget.CoordinatorLayout
                  xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:card_view="http://schemas.android.com/apk/res-auto"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">
              <LinearLayout android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:orientation="vertical">
                  <LinearLayout android:layout_width="match_parent"
                              android:layout_height="0dp"
                              android:background="@drawable/background_login"
                              android:layout_weight="1"
                  android:layout_marginBottom="@dimen/margin_large"></LinearLayout>
          
                  <RelativeLayout
                          android:layout_width="match_parent"
                          android:layout_height="0dp"
                          android:orientation="vertical"
                          android:layout_marginTop="-60dp"
                          android:layout_weight="1"
                  >
          
          
                      <android.support.v7.widget.CardView
                              android:id="@+id/card_view"
                              android:layout_width="match_parent"
                              android:layout_height="match_parent"
                              android:layout_marginLeft="@dimen/margin_large"
                              android:layout_marginRight="@dimen/margin_large"
                              android:layout_marginBottom="30dp"
                              android:background="@android:color/white"
                              card_view:cardCornerRadius="@dimen/margin_card_medium"
                              card_view:cardElevation="@dimen/margin_card_medium">
          
                          <LinearLayout
                                  android:layout_width="match_parent"
                                  android:layout_height="match_parent"
                                  android:orientation="vertical"
                                  android:padding="@dimen/margin_medium_2">
          
                              <TextView android:layout_width="match_parent"
                                      android:layout_height="wrap_content"
                                      android:text="@string/login"
                                      android:gravity="center"
                                      android:textSize="@dimen/text_regular_3x"
                                      android:textColor="@color/secondaryText"/>
          
                              <TextView android:layout_width="match_parent"
                                      android:layout_height="wrap_content"
                                      android:text="@string/email"
                                      android:textSize="@dimen/text_small"
                                      android:textColor="@color/colorBlue"
                                      android:layout_marginTop="@dimen/margin_medium"/>
          
                              <EditText
                                      android:layout_width="match_parent"
                                      android:layout_height="wrap_content"
                                      android:id="@+id/ed_email"
                                      android:textSize="@dimen/text_regular"
                                      android:inputType="textEmailAddress"/>
          
                              <TextView android:layout_width="match_parent"
                                      android:layout_height="wrap_content"
                                      android:textSize="@dimen/text_small"
                                      android:text="@string/password"
                                      android:textColor="@color/colorBlue"
                                      android:layout_marginTop="@dimen/margin_large"/>
          
                              <EditText
                                      android:id="@+id/ed_password"
                                      android:layout_width="match_parent"
                                      android:layout_height="wrap_content"
                                      android:textSize="@dimen/text_regular"
                                      android:inputType="textPassword"/>
          
          
          
                                  <CheckBox
                                          android:layout_width="match_parent"
                                          android:layout_height="wrap_content"
                                          android:text="@string/show_password"
                                          android:textSize="@dimen/text_small"
                                          android:textColor="@color/secondaryText"
                                          android:buttonTint="@color/secondaryText"
                                          android:checked="true"
                                  />
          
          
                          </LinearLayout>
          
                      </android.support.v7.widget.CardView>
          
                  </RelativeLayout>
                  <Button
                  android:layout_width="200dp"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true"
                  android:layout_gravity="center"
                  android:layout_marginTop="-55dp"
                  android:elevation="15dp"
                  android:text="Log In"
                  android:textColor="@color/colorWhite"
                  android:layout_alignParentBottom="true"
                  android:background="@drawable/shapesignup"
          
                  />
          
              </LinearLayout>
              <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="bottom|center"
              android:text="FORGOT PASSWORD?"
              android:layout_centerHorizontal="true"
              android:layout_alignParentBottom="true"
              android:textColor="@color/secondaryText"
              android:textSize="@dimen/text_small"
              android:layout_margin="@dimen/margin_large"
              />
          </android.support.design.widget.CoordinatorLayout>    
          

          OutPut

          此处为 background_login

          <?xml version="1.0" encoding="utf-8"?>
          <shape xmlns:android="http://schemas.android.com/apk/res/android">
              <gradient
                      android:angle="225"
                      android:startColor="@color/colorBlue"
                      android:endColor="#21d6d3" />
          </shape>
          

          【讨论】:

            猜你喜欢
            • 2020-04-11
            • 1970-01-01
            • 1970-01-01
            • 2021-05-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-02-26
            • 1970-01-01
            相关资源
            最近更新 更多