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
You could do this pretty easily with the Constraint Layout library and with the design tab.
Sample photo
Here's the code but I did most of this in the design tab.
<?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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With