ConstraintLayout is behaving inconsistently if a TextView has very fewer texts than other TextView wrapped in horizontal LinearLayout. If a character in left TextView
is not much less than right TextView
then it is working great.
Please refer red color texts and green color texts in attached screenshots.
Below is the XML for layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_F1F1F1"
android:padding="10dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10dp">
<TextView
android:id="@+id/tv_name_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/employee_name"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_date_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_name_header" />
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_date_header" />
<TextView
android:id="@+id/tv_role_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/employee_role"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_name" />
<TextView
android:id="@+id/tv_band_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/employee_band"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_date" />
<TextView
android:id="@+id/tv_role"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_role_header" />
<TextView
android:id="@+id/tv_band"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_band_header" />
<View
android:id="@+id/view_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="@color/color_E1E4EA"
app:layout_constraintTop_toBottomOf="@id/tv_role" />
<LinearLayout
android:id="@+id/ll_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_divider">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginTop="3dp"
android:background="@drawable/circle_shape_green" />
<TextView
android:id="@+id/tv_origin_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text=""
android:textColor="@color/black"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="3dp"
android:background="@drawable/circle_shape_red" />
<TextView
android:id="@+id/tv_destination_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:gravity="right"
android:text=""
android:textColor="@color/black"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_justification_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/justification"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/ll_address" />
<TextView
android:id="@+id/tv_justification"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_justification_header" />
<TextView
android:id="@+id/tv_vehicle_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/vehicle_type"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_justification" />
<TextView
android:id="@+id/tv_vehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_vehicle_header" />
<TextView
android:id="@+id/tv_Duration_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/distance"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_justification" />
<TextView
android:id="@+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_Duration_header" />
<TextView
android:id="@+id/tv_start_time_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/start_time"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_vehicle" />
<TextView
android:id="@+id/tv_end_time_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/end_time"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_duration" />
<TextView
android:id="@+id/tv_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_start_time_header" />
<TextView
android:id="@+id/tv_end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_end_time_header" />
<TextView
android:id="@+id/tv_distance_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/trip_distance"
android:textColor="@color/color_999999"
android:textSize="12sp"
app:layout_constraintTop_toBottomOf="@id/tv_start_time" />
<TextView
android:id="@+id/tv_edited_distance_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/edited_distance"
android:textColor="@color/color_999999"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_end_time" />
<TextView
android:id="@+id/tv_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_distance_header" />
<TextView
android:id="@+id/tv_edited_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/color_D15900"
android:textSize="14sp"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_edited_distance_header" />
<TextView
android:id="@+id/tv_edit_reason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="14sp"
android:visibility="gone"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_distance" />
<LinearLayout
android:id="@+id/ll_reject_reason"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_edit_reason">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/manager_reject_reason"
android:textColor="@color/color_999999"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_rejection_reason"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="@+id/bt_back"
style="@style/FlatButton"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:gravity="left|center_vertical"
android:paddingLeft="0dp"
android:text="@string/back"
android:textAllCaps="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/ll_reject_reason" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
Please ignore my English.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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="#F1F1F1">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:layout_margin = "10dp">
<TextView
android:id="@+id/tv_name_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="employee_name"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/tv_name"
/>
<TextView
android:id="@+id/tv_date_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date_header"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/tv_name_header"
app:layout_constraintBottom_toTopOf="@+id/tv_date"/>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_name_header"
app:layout_constraintBottom_toTopOf="@+id/tv_role_header"
/>
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@+id/tv_date_header"
app:layout_constraintLeft_toLeftOf="@+id/tv_date_header"
app:layout_constraintBottom_toTopOf="@+id/tv_band_header"
/>
<TextView
android:id="@+id/tv_role_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="employee_role"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintTop_toBottomOf="@+id/tv_name" />
<TextView
android:id="@+id/tv_band_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:text="employee_band"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="@+id/tv_date"
app:layout_constraintTop_toBottomOf="@+id/tv_date"
/>
<TextView
android:id="@+id/tv_role"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="role"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="@+id/tv_role_header"
app:layout_constraintTop_toBottomOf="@+id/tv_role_header" />
<TextView
android:id="@+id/tv_band"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="band"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="@+id/tv_band_header"
app:layout_constraintTop_toBottomOf="@+id/tv_band_header" />
<View
android:id="@+id/view_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#E1E4EA"
app:layout_constraintTop_toBottomOf="@+id/tv_role"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<LinearLayout
android:id="@+id/ll_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_divider">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginTop="3dp"
/>
<TextView
android:id="@+id/tv_origin_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="origin_address \n origin_address"
android:textColor="#000000"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="3dp"
/>
<TextView
android:id="@+id/tv_destination_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address \n destination_address "
android:textColor="#000000"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_justification_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="justification_header"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_address" />
<TextView
android:id="@+id/tv_justification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="justification"
android:textColor="#000000"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="@+id/tv_justification_header"
app:layout_constraintTop_toBottomOf="@+id/tv_justification_header" />
<TextView
android:id="@+id/tv_vehicle_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="vehicle_type"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_justification" />
<TextView
android:id="@+id/tv_vehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="vehicle"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_vehicle_header" />
<TextView
android:id="@+id/tv_Duration_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="distance"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_justification" />
<TextView
android:id="@+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="duration"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_Duration_header" />
<TextView
android:id="@+id/tv_start_time_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="start_time"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_vehicle" />
<TextView
android:id="@+id/tv_end_time_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="end_time"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_duration" />
<TextView
android:id="@+id/tv_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start_time"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_start_time_header" />
<TextView
android:id="@+id/tv_end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="end_time"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_end_time_header" />
<TextView
android:id="@+id/tv_distance_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="trip_distance"
android:textColor="#999999"
android:textSize="12sp"
app:layout_constraintTop_toBottomOf="@+id/tv_start_time"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/tv_edited_distance_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="edited_distance"
android:textColor="#999999"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_end_time" />
<TextView
android:id="@+id/tv_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="distance"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_distance_header" />
<TextView
android:id="@+id/tv_edited_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="edited_distance"
android:textColor="#D15900"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_edited_distance_header" />
<TextView
android:id="@+id/tv_edit_reason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="edit_reason"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_distance" />
<LinearLayout
android:id="@+id/ll_reject_reason"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_edit_reason">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="manager_reject_reason"
android:textColor="#999999"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_rejection_reason"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="rejection_reason"
android:textColor="#000000"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="@+id/bt_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:gravity="center"
android:text="Back"
android:textAllCaps="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_reject_reason"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="12dp"
android:layout_marginBottom="14dp"
android:layout_marginStart="12dp"/>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With