Gap between left drawable and text in textview - android

There is a long gap between drawable left and the text in text view.
I have added drawable padding but that does not seem to work. Here is my code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="24dp"
android:background="#0B6159"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="16dp"
android:text="Add Address"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:fontFamily="#font/aladin"
android:gravity="center"
android:drawableLeft="#drawable/ic_add_circle_outline_black_24dp"
android:drawableStart="#drawable/ic_add_circle_outline_black_24dp"
android:drawablePadding="10dp"
/>
</LinearLayout>
How can I bring the drawable close to my text

Remove android:gravity="center"from textview :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="24dp"
android:background="#0B6159"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="16dp"
android:text="Add Address"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:fontFamily="#font/aladin"
android:drawableLeft="#drawable/ic_add_circle_outline_black_24dp"
android:drawableStart="#drawable/ic_add_circle_outline_black_24dp"
android:drawablePadding="10dp"
/>
</LinearLayout>
Use drawablePadding for maintain gap according to your need.

Thanks to Rishab, found a work around
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#0B6159">
<TextView
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="32dp"
android:layout_marginRight="16dp"
android:text="Add Address"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:fontFamily="#font/aladin"
android:drawableLeft="#drawable/ic_add_circle_outline_black_24dp"
android:drawableStart="#drawable/ic_add_circle_outline_black_24dp"
android:drawablePadding="10dp"
/>
</LinearLayout>

Related

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>

Android: How to get 3 elements side by side

I'm trying to have 3 elements side by side like this:
The second image is never displayed. Where is my mistake ?
<ImageView
android:id="#+id/asset_cat_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/asset_cat_image"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/asset_cat_image">
<TextView
android:id="#+id/asset_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:maxLines="1"
android:textColor="#color/cardview_head"
android:ellipsize="end"
tools:text="Main Text"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp" />
<TextView
android:id="#+id/asset_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="14sp"
android:textColor="#color/cardview_subhead"
tools:text="Sub Text"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp" />
</LinearLayout>
<ImageView
android:id="#+id/collapseimg"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#mipmap/ic_launcher" />
</RelativeLayout>
While LinearLayouts width is match_parent it displaces every view after it by default. To avoid it you need to say what view should be placed after it. In your case it should be:
<LinearLayout
...
android:layout_toRightOf="#+id/asset_cat_image"
android:layout_toLeftOf="#+id/collapseimg">
Then align your second image to the right side:
<ImageView
...
android:layout_alignParentRight="true"/>

ConstraintLayout is gone when the width is set to "match_constraint"

I am making CardView with three ConstraintLayouts. One ConstraintLayout wraps two ConstraintLayout which are located side by side.
The problem is that right-sided ConstraintLayout is gone if the width is set to match_constraint. It seems fine in Android Studio, but it is gone when I run this on my phone. I assume that the reason "match_constraint" sets the width to 0dp. I want the right-sided Constraint to dynamically change the width depending on the phone.
The below is my layout XML file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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.support.v7.widget.CardView
android:id="#+id/cv_result_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:padding="8dp"
card_view:cardBackgroundColor="#eee"
card_view:cardCornerRadius="5dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_left-panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#color/blank_color"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/iv_result_quiz_detail"
android:layout_width="140dp"
android:layout_height="115dp"
android:layout_margin="4dp"
android:contentDescription="#string/iv_result_quiz_detail"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:srcCompat="#mipmap/ic_launcher" />
<TextView
android:id="#+id/tv_no_of_likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/iv_result_quiz_detail"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_toEndOf="#+id/chb_like"
android:gravity="top"
android:text="#string/tv_no_of_likes"
android:textSize="12sp"
android:textStyle="italic"
card_view:layout_constraintStart_toEndOf="#+id/chb_like"
card_view:layout_constraintTop_toBottomOf="#+id/iv_result_quiz_detail" />
<CheckBox
android:id="#+id/chb_like"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_below="#+id/iv_result_quiz_detail"
android:layout_margin="4dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/selector_like"
android:button="#null"
android:contentDescription="#string/ib_like"
android:scaleType="fitXY"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintStart_toStartOf="#+id/iv_result_quiz_detail"
card_view:layout_constraintTop_toBottomOf="#+id/iv_result_quiz_detail" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_right_panel"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="#color/blank_color"
card_view:layout_constraintBottom_toBottomOf="#+id/cl_left-panel"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toEndOf="#+id/cl_left-panel"
card_view:layout_constraintTop_toTopOf="#+id/cl_left-panel">
<TextView
android:id="#+id/tv_quiz_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:maxLines="2"
android:text="#string/test_question"
android:textSize="12sp"
android:textStyle="bold"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_choice_01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quiz_desc"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:background="#drawable/shape_round_button_mint"
android:ellipsize="end"
android:gravity="start"
android:maxLines="1"
android:text="#string/test_choice"
android:textSize="12sp"
card_view:layout_constraintStart_toStartOf="#+id/tv_quiz_desc"
card_view:layout_constraintTop_toBottomOf="#+id/tv_quiz_desc" />
<TextView
android:id="#+id/tv_choice_02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_choice_01"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="start"
android:maxLines="1"
android:text="#string/test_choice"
android:textSize="12sp"
card_view:layout_constraintStart_toStartOf="#+id/tv_quiz_desc"
card_view:layout_constraintTop_toBottomOf="#+id/tv_choice_01" />
<TextView
android:id="#+id/tv_choice_03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_choice_02"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="start"
android:maxLines="1"
android:text="#string/test_choice"
android:textSize="12sp"
card_view:layout_constraintStart_toStartOf="#+id/tv_quiz_desc"
card_view:layout_constraintTop_toBottomOf="#+id/tv_choice_02" />
<TextView
android:id="#+id/tv_choice_04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_choice_03"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:ellipsize="end"
android:gravity="start"
android:maxLines="1"
android:text="#string/test_choice"
android:textSize="12sp"
card_view:layout_constraintStart_toStartOf="#+id/tv_quiz_desc"
card_view:layout_constraintTop_toBottomOf="#+id/tv_choice_03" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
What I expected is like
Maybe your first ConstraintLayout (that has fixed width) occupies the entire screen.
Try using layout_constraintHorizontal_weight to determine the portion of the screen that each layout occupies.
Left layout:
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_left-panel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#color/blank_color"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="#id/cl_right_panel"
card_view:layout_constraintHorizontal_weight="1"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent">
Right layout:
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_right_panel"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="#color/blank_color"
card_view:layout_constraintBottom_toBottomOf="#+id/cl_left-panel"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_weight="1.5"
card_view:layout_constraintStart_toEndOf="#+id/cl_left-panel"
card_view:layout_constraintTop_toTopOf="#+id/cl_left-panel">
Note: You don't need the root LinearLayout

highlighting items of recyclerView

I want to highlight the selected list item totally, not only background color but the whole list item should have same color.
This is the one without highlighting
I want the output as this was
I am getting just the background color. I have used this code
view.setBackgroundResource(R.color.white);
I am getting like this as output
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/alert_Item"
android:layout_marginTop="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:background="#drawable/list_corners"
>
<ImageView
android:id="#+id/imageView3"
android:layout_width="8dp"
android:layout_height="13dp"
/>
<TextView
android:id="#+id/date"
android:layout_width="108dp"
android:layout_height="13dp"
android:text="member name"
android:textSize="10sp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:id="#+id/memberName"
android:layout_width="98dp"
android:layout_height="13dp"
android:layout_alignParentRight="true"
android:text="member name"
android:textAlignment="textEnd"
android:textSize="10sp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:id="#+id/alertId"
android:layout_width="132dp"
android:layout_height="15dp"
android:text="alert id"
android:textSize="12sp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:id="#+id/alertName"
android:layout_width="72dp"
android:layout_height="13dp"
android:layout_alignBaseline="#+id/alertId"
android:layout_alignParentRight="true"
android:layout_marginTop="2dp"
android:text="alert name"
android:textAlignment="textEnd"
android:textSize="10sp"
android:textColor="#color/textColorPrimary"/>
</RelativeLayout>

Categories

Resources