I am trying a layout which has following general layout hierarchy ConstraintLayout>CardView>ConstraintLayout>Button.
The 2nd constraintLayout must stick to Bottom Right of cardView.
Expected Result:
But the constraints inside Card View are not working.
I have first tried replacing 2nd ConstraintLayout with LinearLayout but it didn't helped too. The constraints are having no effect on them.
<?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"
tools:context=".home_fragment"
android:id="@+id/home_fragment">
<android.support.v7.widget.CardView
android:id="@+id/first_card"
android:layout_width="200dp"
android:layout_height="100dp"
app:cardBackgroundColor="@color/card_color"
app:cardCornerRadius="15dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="200dp"
>
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1 "
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/second_card"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginTop="56dp"
app:cardBackgroundColor="@color/card_color"
app:cardCornerRadius="20dp"
app:layout_constraintStart_toStartOf="@id/first_card"
app:layout_constraintTop_toBottomOf="@id/first_card">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2 "
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
But here the 2nd ConstraintLayout is sticked to Top-Left of CardView. I want it to be sticked at Bottom-Right of CardView. The actual result:
Set your inner ConstraintLayout like this:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1 "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</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