how to edit xml ,add RecyclerView - android

I'm a newbie and I'm trying to edit quiz app
Some of the answers are long and need to be this xml Recycler View
Is there a way to add it or I have to create a new one?
please help
I'm a newbie and I'm trying to edit quiz app
Some of the answers are long and need to be this xml Recycler View
Is there a way to add it or I have to create a new one?
please help
<androidx.constraintlayout.widget.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=".QuizActivity">
<View
android:id="#+id/view4"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:background="#drawable/background_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/question"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:fontFamily="#font/roboto_bold"
android:gravity="center"
android:text=""
android:textColor="#color/color_white"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="#+id/view5"
app:layout_constraintEnd_toEndOf="#+id/view5"
app:layout_constraintStart_toStartOf="#+id/view5"
app:layout_constraintTop_toTopOf="#+id/view5" />
<TextView
android:id="#+id/option_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/option_unselected"
android:onClick="onClick"
android:padding="15dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="#+id/view5"
app:layout_constraintStart_toStartOf="#+id/view5"
app:layout_constraintTop_toBottomOf="#+id/imageView4" />
<TextView
android:id="#+id/option_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/option_unselected"
android:onClick="onClick"
android:padding="15dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="#+id/option_1"
app:layout_constraintStart_toStartOf="#+id/option_1"
app:layout_constraintTop_toBottomOf="#+id/option_1" />
<TextView
android:id="#+id/option_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/option_unselected"
android:onClick="onClick"
android:padding="15dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="#+id/option_2"
app:layout_constraintStart_toStartOf="#+id/option_2"
app:layout_constraintTop_toBottomOf="#+id/option_2" />
<TextView
android:id="#+id/option_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/option_unselected"
android:onClick="onClick"
android:padding="15dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="#+id/option_3"
app:layout_constraintStart_toStartOf="#+id/option_3"
app:layout_constraintTop_toBottomOf="#+id/option_3" />
<Button
android:id="#+id/nextBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="150dp"
android:background="#drawable/button_2"
android:onClick="onClick"
android:text="التالي"
android:textColor="#color/color_white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/option_4" />
</androidx.constraintlayout.widget.ConstraintLayout>

Related

Recyclerview layout in dialog box

I am facing a problem while opening recyclerview in a dialog box. The layout in the recyclerview is overlapping and cutting when I open this in a dialog box same like this:
But, my original layout is look like this:
and here is the code for my layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
android:layout_margin="8dp"
android:layout_marginBottom="14dp"
android:elevation="10dp"
android:padding="8dp"
app:cardCornerRadius="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/corner_layout"
android:paddingTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/r_field_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Admission No."
android:textColor="#009EBB"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/r_d_field_name"
app:layout_constraintStart_toStartOf="#+id/r_d_field_name"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />
<TextView
android:id="#+id/admission_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="45654"
android:textColor="#555555"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#+id/st_name"
app:layout_constraintStart_toStartOf="#+id/st_name"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/r_d_field_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Name"
android:textColor="#009EBB"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toTopOf="#+id/p_a_field_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/r_field_name"
tools:ignore="RtlHardcoded" />
<TextView
android:id="#+id/st_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Harikant Sharma"
android:textColor="#555555"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#+id/st_father_mother_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/r_d_field_name"
app:layout_constraintTop_toBottomOf="#+id/admission_no" />
<TextView
android:id="#+id/p_a_field_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Parents Name"
android:textColor="#009EBB"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/btn_call_st"
app:layout_constraintStart_toStartOf="#+id/r_d_field_name"
app:layout_constraintTop_toBottomOf="#+id/r_d_field_name"
tools:ignore="RtlHardcoded" />
<TextView
android:id="#+id/st_father_mother_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Suresh Kumar Sharma"
android:textColor="#555555"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#+id/btn_view_st_profile"
app:layout_constraintStart_toStartOf="#+id/st_name"
app:layout_constraintTop_toBottomOf="#+id/st_name" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/btn_view_st_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:layout_marginBottom="12dp"
android:gravity="center"
android:src="#drawable/view"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/btn_call_st"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9"
app:tint="#color/white" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/btn_call_st"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#E10751"
android:gravity="center"
android:src="#drawable/phone"
app:layout_constraintBottom_toBottomOf="#+id/btn_view_st_profile"
app:layout_constraintEnd_toStartOf="#+id/btn_view_st_profile"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/btn_view_st_profile"
app:tint="#color/white" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
If you constrain both left and right, you need to set width=0dp
<TextView
android:id="#+id/st_name"
android:layout_width="0dp" <-- change to 0dp
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Harikant Sharma"
android:textColor="#555555"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#+id/st_father_mother_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/r_d_field_name"
app:layout_constraintTop_toBottomOf="#+id/admission_no" />

Align textviews in left and right side of a linear layout?

I currently doing one of the project from "Google Android Dev". I am facing a problem in my layout design. Kindly help me how to align one textview in left side and right side of a linear layout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="194dp"
android:layout_marginBottom="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="#+id/textAppearanceHeadline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#drawable/faye" />
<TextView
android:id="#+id/textAppearanceHeadline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Faye"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<LinearLayout
android:id="#+id/textAppearanceBody1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textAppearanceHeadline6"
app:layout_constraintTop_toBottomOf="#+id/textAppearanceHeadline6">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:text="Age : 7"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|right"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Hobbies: Sunbathing"
android:textColor="#5A5656" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I am new to android so you are most welcome for code review.
Try to change your layout like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="194dp"
android:layout_marginBottom="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="#+id/textAppearanceHeadline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#drawable/faye" />
<TextView
android:id="#+id/textAppearanceHeadline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Faye"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<LinearLayout
android:id="#+id/textAppearanceBody1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textAppearanceHeadline6"
app:layout_constraintTop_toBottomOf="#+id/textAppearanceHeadline6">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|start"
android:text="Age : 7"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hobbies: Sunbathing"
android:gravity="center"
android:textColor="#5A5656" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Use it like this
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:weight="1"
android:layout_height="wrap_content"
android:text="Age : 7"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Hobbies: Sunbathing"
android:textColor="#5A5656" />
weight here will allow the first textview to take all the space and will leave the required space for the hobby textview.
Use it as per your requirement.

How to get the middle part of the activity to be scrollable?

I am trying to get something like this in one of my activities:
attraction detailed view
I want the image to be fixed at the top, the middle bit with the text to be scrollable as description and short description will have quite a lot of text, and the buttons to be fixed to the bottom. only the middle one is permanent visibility, the margin ones are hidden or visible depending type of attraction listed.
I tried to enclose in linear layouts but didnt work, most probably my mistake.
My xml file is :
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
tools:context=".DetailedViewActivity">
<TextView
android:id="#+id/textViewDetailedName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:fontFamily="#font/share_bold"
android:text="#string/name"
android:textAlignment="center"
android:textColor="#color/colorDark"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView4" />
<TextView
android:id="#+id/textViewDetailedAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="#font/share"
android:text="#string/address"
android:textAlignment="viewStart"
android:textColor="#color/colorDark"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedInfoAddress"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedInfoAddress"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedInfoAddress" />
<TextView
android:id="#+id/textViewDetailedPostCode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="#font/share"
android:text="#string/post_code"
android:textAlignment="viewStart"
android:textColor="#color/colorDark"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedInfoPostCode"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedInfoPostCode"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedInfoPostCode" />
<TextView
android:id="#+id/textViewDetailedShortDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="#font/share"
android:text="#string/short_description"
android:textAlignment="viewStart"
android:textColor="#color/colorDark"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedInfoShortDesc"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedInfoShortDesc"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedInfoShortDesc" />
<TextView
android:id="#+id/textViewDetailedDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="#font/share"
android:text="#string/description"
android:textAlignment="viewStart"
android:textColor="#color/colorDark"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedName"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedName"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedInfoDescription" />
<TextView
android:id="#+id/textViewDetailedPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="#font/share"
android:text="#string/price"
android:textAlignment="viewStart"
android:textColor="#color/colorDark"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedName"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedName"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedInfoPrice" />
<TextView
android:id="#+id/textViewDetailedInfoAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="#font/share"
android:text="#string/address"
android:textColor="#color/colorTeal"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedName"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedName"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedName" />
<TextView
android:id="#+id/textViewDetailedInfoPostCode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/share"
android:text="#string/post_code"
android:textColor="#color/colorTeal"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedAddress"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedAddress"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedAddress" />
<TextView
android:id="#+id/textViewDetailedInfoShortDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/share"
android:text="#string/short_description"
android:textColor="#color/colorTeal"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedPostCode"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedPostCode"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedPostCode" />
<TextView
android:id="#+id/textViewDetailedInfoDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/share"
android:text="#string/description"
android:textColor="#color/colorTeal"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedShortDesc"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedShortDesc"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedShortDesc" />
<TextView
android:id="#+id/textViewDetailedInfoPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/share"
android:text="#string/price"
android:textColor="#color/colorTeal"
app:layout_constraintEnd_toEndOf="#+id/textViewDetailedDesc"
app:layout_constraintStart_toStartOf="#+id/textViewDetailedDesc"
app:layout_constraintTop_toBottomOf="#+id/textViewDetailedDesc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="match_parent"
android:layout_height="270dp"
android:scaleType="fitXY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_image" />
<Button
android:id="#+id/btnReadReviews"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginBottom="32dp"
android:fontFamily="#font/share_bold"
android:text="#string/read_reviews"
android:textAllCaps="false"
android:textColor="#color/colorDark"
android:textSize="14sp"
app:backgroundTint="#color/colorPrimary"
app:cornerRadius="7dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/btnBook"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:fontFamily="#font/share_bold"
android:text="#string/book"
android:textAllCaps="false"
android:textColor="#color/colorDark"
android:textSize="14sp"
app:backgroundTint="#color/colorPrimary"
app:cornerRadius="7dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/btnPostReview"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:fontFamily="#font/share_bold"
android:text="#string/add_review"
android:textAllCaps="false"
android:textColor="#color/colorDark"
android:textSize="14sp"
app:backgroundTint="#color/colorPrimary"
app:cornerRadius="7dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can wrap all scroll views into ScroolView and use another ConstraintLayout inside the ScroolView. You can found an example here

dynamic height alignment in constraintlayout

I have 3 textview in which the text can change dynamically, I need to make them equal to each other, whose height is greater than that height and take for all. I'm trying using barriers but don't get positive result, also i try set all textviews height 0dp but all textviews then disappeared, i can set the height for one textview wrap_content and for another 0dp but then they will be equal only in the first textview. When I used linearlayout I did it, but with constraintlayout i don't understand how do it.
xml:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:fontFamily="#font/gothic_bold"
android:gravity="center"
android:text="test 1"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/label_zone2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/coefficient_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="#font/gothic"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone1"
app:layout_constraintStart_toStartOf="#+id/label_zone1"
app:layout_constraintTop_toBottomOf="#+id/label_zone1" />
<TextView
android:id="#+id/consumption_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/input_border"
android:fontFamily="#font/gothic"
android:gravity="center|center_vertical"
android:text="1234567"
android:textColor="#color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="#+id/coefficient_zone1"
app:layout_constraintStart_toStartOf="#+id/coefficient_zone1"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<TextView
android:id="#+id/label_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:fontFamily="#font/gothic_bold"
android:gravity="center"
android:text="test 2"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/label_zone3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/label_zone1"
app:layout_constraintTop_toTopOf="#+id/label_zone1" />
<TextView
android:id="#+id/coefficient_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="#font/gothic"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone2"
app:layout_constraintStart_toStartOf="#+id/label_zone2"
app:layout_constraintTop_toBottomOf="#+id/label_zone2" />
<TextView
android:id="#+id/consumption_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/input_border"
android:fontFamily="#font/gothic"
android:gravity="center|center_vertical"
android:text="1234567"
android:textColor="#color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="#+id/coefficient_zone2"
app:layout_constraintStart_toStartOf="#+id/coefficient_zone2"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<TextView
android:id="#+id/label_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:fontFamily="#font/gothic_bold"
android:gravity="center"
android:text="test 3"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/label_zone2"
app:layout_constraintTop_toTopOf="#+id/label_zone2" />
<TextView
android:id="#+id/coefficient_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="#font/gothic"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone3"
app:layout_constraintStart_toStartOf="#+id/label_zone3"
app:layout_constraintTop_toBottomOf="#+id/label_zone3" />
<TextView
android:id="#+id/consumption_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/input_border"
android:fontFamily="#font/gothic"
android:gravity="center|center_vertical"
android:text="12345678"
android:textColor="#color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="#+id/coefficient_zone3"
app:layout_constraintStart_toStartOf="#+id/coefficient_zone3"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="coefficient_zone1,coefficient_zone2,coefficient_zone3" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3" />
<TextView
android:id="#+id/label_calculated_indicators"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="#font/gothic_bold"
android:gravity="center"
android:text="title title title title"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone3"
app:layout_constraintStart_toStartOf="#+id/label_zone1"
app:layout_constraintTop_toBottomOf="#+id/consumption_zone1" />
</androidx.constraintlayout.widget.ConstraintLayout>
As Nikos Hidalgo stated in the comment to your question, this is a common question that is asked on Stack Overflow. I have come across four ways to accomplish a common width and/or common height for a set of views. Unfortunately, none is ideal.
Here is a screen shot showing the three of the four ways to get to common dimensions. The XML for this screen is at the end of this post.
Embedded LinearLayout
This is probably the easiest way. Place the TextViews in a horizontal LinearLayout setting their heights to MATCH_PARENT. Set the height of the LinearLayout to WRAP_CONTENT and all will work out. The benefit of this way is its simplicity. Negatives include the overhead of a nested layout and the inability for any of the views within the LinearLayout to be connected to any view outside the LinearLayout - they become an island.
Invisible Views
This is probably the most complicated way of doing things but it may be OK depending upon the layout. The basic problem with setting up barriers to adjust the height of a set of views is that the barrier placement depends upon the height of the views and the height of the views depend upon the barrier placement. This is a referential quandary and does not work with the current version of ConstraintLayout.
The invisible view solution is to duplicate the views for which height is to be adjusted as invisible views. Set a top and a bottom barrier to these invisible views. Set the height of the visible views to MATCH_CONSTRAINTS and connect the tops to the top barrier and the bottom to the bottom barrier.
The benefit of this approach is that it is totally flat and involves just the ConstraintLayout. The drawbacks are that it increases the view count by the number of views to be adjusted, its complexity and everything that complexity entails.
Constraint Layout Size Helper
The third approach is to use a custom ConstraintHelper to change the heights of the views. The custom ConstraintHelper is inserted into the XML for the layout like any other view and made to reference the views to be adjusted.
The benefit of this approach is that the changes are all kept within the XML. The negative is that a custom class must be referenced and maintained.
Listener to Update Width/Height
This final approach is to custom code the height adjustments using a global layout listener, a layout listener or the like. This is similar to the ConstraintHelper approach but exists outside of the XML and may not be well encapsulated.
It might also be possible to code custom views to set heights of views to the greatest height either with a custom ConstraintLayout or a custom TextView.
Sample Layout
<TextView
android:id="#+id/textView2_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Embedded LinearLayout"
app:layout_constraintBottom_toTopOf="#+id/layout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:ignore="HardcodedText" />
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="#android:color/holo_blue_bright"
app:layout_constraintBottom_toTopOf="#id/textView3_0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2_0">
<TextView
android:id="#+id/textView2_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView2_2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="24dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView2_3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="24dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
tools:ignore="HardcodedText" />
</LinearLayout>
<TextView
android:id="#+id/textView3_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Invisible Views"
app:layout_constraintBottom_toTopOf="#id/textView3_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/layout2"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView3_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="#+id/textView3_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/textView3_2"
tools:visibility="invisible"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView3_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#id/textView5_0"
app:layout_constraintEnd_toStartOf="#+id/textView3_3"
app:layout_constraintStart_toEndOf="#+id/textView3_1"
app:layout_constraintTop_toBottomOf="#id/textView3_0"
tools:visibility="invisible"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView3_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView3_2"
app:layout_constraintTop_toTopOf="#+id/textView3_2"
tools:visibility="invisible"
tools:ignore="HardcodedText" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrierTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="textView3_1,textView3_2,textView3_3" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrierBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="textView3_1,textView3_2,textView3_3" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/holo_blue_bright"
app:layout_constraintBottom_toTopOf="#id/barrierBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/barrierTop" />
<TextView
android:id="#+id/textView4_1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#id/barrierBottom"
app:layout_constraintEnd_toStartOf="#+id/textView4_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/barrierTop"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView4_2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#id/barrierBottom"
app:layout_constraintEnd_toStartOf="#+id/textView4_3"
app:layout_constraintStart_toEndOf="#+id/textView4_1"
app:layout_constraintTop_toBottomOf="#+id/barrierTop"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView4_3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
app:layout_constraintBottom_toTopOf="#id/barrierBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView4_2"
app:layout_constraintTop_toBottomOf="#+id/barrierTop"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView5_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="ConstraintLayout Size Helper"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/barrierBottom"
tools:ignore="HardcodedText" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/holo_blue_bright"
app:layout_constraintBottom_toBottomOf="#id/textView5_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/textView5_1" />
<TextView
android:id="#+id/textView5_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="#+id/textView5_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/textView5_2"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView5_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="#+id/textView5_3"
app:layout_constraintStart_toEndOf="#+id/textView5_1"
app:layout_constraintTop_toBottomOf="#+id/textView5_0"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/textView5_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:background="#android:color/white"
android:gravity="center"
android:text="This is the TextView that has the maximum height."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView5_2"
app:layout_constraintTop_toTopOf="#+id/textView5_2"
tools:ignore="HardcodedText" />
<com.example.constraintsizehelper.ConstraintSizeHelper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="textView5_1,textView5_2,textView5_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:setCommonWidth="true"
app:setCommonHeight="true"
tools:layout_height="120dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Here is a reduced version of your layout using a Constraint Size Helper class (not provided):
And its XML:
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:gravity="center"
android:text="test 1"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/label_zone2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/coefficient_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone1"
app:layout_constraintStart_toStartOf="#+id/label_zone1"
app:layout_constraintTop_toBottomOf="#+id/label_zone1" />
<TextView
android:id="#+id/consumption_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/input_border"
android:gravity="center|center_vertical"
android:text="0"
android:textColor="#color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="#+id/coefficient_zone1"
app:layout_constraintStart_toStartOf="#+id/coefficient_zone1"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<TextView
android:id="#+id/label_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:gravity="center"
android:text="test 2"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/label_zone3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/label_zone1"
app:layout_constraintTop_toTopOf="#+id/label_zone1" />
<TextView
android:id="#+id/coefficient_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone2"
app:layout_constraintStart_toStartOf="#+id/label_zone2"
app:layout_constraintTop_toBottomOf="#+id/label_zone2" />
<TextView
android:id="#+id/consumption_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/input_border"
android:gravity="center|center_vertical"
android:text="12345678"
android:textColor="#color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="#+id/coefficient_zone2"
app:layout_constraintStart_toStartOf="#+id/coefficient_zone2"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<TextView
android:id="#+id/label_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:gravity="center"
android:text="test 3"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/label_zone2"
app:layout_constraintTop_toTopOf="#+id/label_zone2" />
<TextView
android:id="#+id/coefficient_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone3"
app:layout_constraintStart_toStartOf="#+id/label_zone3"
app:layout_constraintTop_toBottomOf="#+id/label_zone3" />
<TextView
android:id="#+id/consumption_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/input_border"
android:gravity="center|center_vertical"
android:text="1234567890"
android:textColor="#color/orange"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="#+id/coefficient_zone3"
app:layout_constraintStart_toStartOf="#+id/coefficient_zone3"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="coefficient_zone1,coefficient_zone2,coefficient_zone3" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3" />
<TextView
android:id="#+id/label_calculated_indicators"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="title title title title"
android:textAllCaps="true"
android:textColor="#color/blue"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone3"
app:layout_constraintStart_toStartOf="#+id/label_zone1"
app:layout_constraintTop_toBottomOf="#+id/consumption_zone1" />
<com.example.myapplication.ConstraintSizeHelper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_height="120dp"
app:setCommonWidth="false"
app:setCommonHeight="true"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3"/>
</androidx.constraintlayout.widget.ConstraintLayout>
As per I understand your question try to use horizontal chain for "consumption_zone" all textviews.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:gravity="center"
android:text="test 1"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/label_zone2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/coefficient_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone1"
app:layout_constraintStart_toStartOf="#+id/label_zone1"
app:layout_constraintTop_toBottomOf="#+id/label_zone1" />
<TextView
android:id="#+id/label_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:gravity="center"
android:text="test 2"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/label_zone3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/label_zone1"
app:layout_constraintTop_toTopOf="#+id/label_zone1" />
<TextView
android:id="#+id/coefficient_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone2"
app:layout_constraintStart_toStartOf="#+id/label_zone2"
app:layout_constraintTop_toBottomOf="#+id/label_zone2" />
<TextView
android:id="#+id/coefficient_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="text="
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/label_zone3"
app:layout_constraintStart_toStartOf="#+id/label_zone3"
app:layout_constraintTop_toBottomOf="#+id/label_zone3" />
<TextView
android:id="#+id/label_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:gravity="center"
android:text="test 3"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/label_zone2"
app:layout_constraintTop_toTopOf="#+id/label_zone2" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="coefficient_zone1,coefficient_zone2,coefficient_zone3" />
<TextView
android:id="#+id/consumption_zone1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center|center_vertical"
android:text="123456789"
android:textColor="#color/colorAccent"
android:textSize="24sp"
android:layout_marginStart="10dp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toStartOf="#+id/consumption_zone2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<TextView
android:id="#+id/consumption_zone2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center|center_vertical"
android:text="123456789"
android:textColor="#color/colorAccent"
android:textSize="24sp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toStartOf="#+id/consumption_zone3"
app:layout_constraintStart_toEndOf="#+id/consumption_zone1"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<TextView
android:id="#+id/consumption_zone3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center|center_vertical"
android:text="123456789"
android:textColor="#color/colorAccent"
android:textSize="24sp"
android:layout_marginEnd="10dp"
app:layout_constraintBottom_toBottomOf="#+id/barrier2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/consumption_zone2"
app:layout_constraintTop_toBottomOf="#+id/barrier" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="consumption_zone1,consumption_zone2,consumption_zone3" />
</androidx.constraintlayout.widget.ConstraintLayout>

adding Edittext and Button when clicking a button in kotlin

my app needs an add button that adds two Edittext and another button every time they click the add button
adds again the same three things under the added ones, I attached a screenshot of how my app suppose to work, I really need help in this I am new in android development.
here is my activity layout
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Mark_calc">
<include
android:id="#+id/Mark_calcTB"
layout="#layout/toolbar"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_add" />
<TextView
android:id="#+id/Box_1"
android:layout_width="0dp"
android:layout_height="207dp"
android:layout_marginStart="10dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="10dp"
android:background="#drawable/rounded_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Mark_calcTB" />
<TextView
android:id="#+id/Total_MarksTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:text="Total marks:"
android:textColor="#android:color/white"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/Box_1" />
<TextView
android:id="#+id/result_total_marksTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:layout_marginEnd="85dp"
android:text="0"
android:textColor="#android:color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Mark_calcTB" />
<TextView
android:id="#+id/total_hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginBottom="40dp"
android:text="Total hours:"
android:textColor="#android:color/white"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/Box_1"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/result_total_hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="84dp"
android:layout_marginBottom="40dp"
android:text="0"
android:textColor="#android:color/white"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="#+id/Box_1"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="#+id/mark1"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="Mark%"
android:inputType="numberSigned"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Box_1" />
<EditText
android:id="#+id/hours1"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="Hours"
android:inputType="numberSigned"
app:layout_constraintStart_toEndOf="#+id/mark1"
app:layout_constraintTop_toBottomOf="#+id/Box_1" />
<Button
android:id="#+id/delete_button"
android:layout_width="35dp"
android:layout_height="38dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:background="#drawable/ic_delete"
app:layout_constraintStart_toEndOf="#+id/hours1"
app:layout_constraintTop_toBottomOf="#+id/Box_1" />
</androidx.constraintlayout.widget.ConstraintLayout>
and here is a screenshot of how it should work.
Take Recyclerview and when you click on add Button add the data to your ArrayList and update the adapter to NotifyDataSetChanges.

Categories

Resources