Im facing issue, where imageview is getting pushed out by inner linear layout. The views are wrapped inside an outer linear layout. I tried a constraint layout chaining, but the view needed a constraint from left and right side, which resulted in aligning the view into the center, which is not desired. I want the view, to be aligned to the left side. Does anybody know?
<?xml version="1.0" encoding="utf-8"?>
<!--RIGHT ITEM-->
<LinearLayout
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:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_marginLeft="10dp"
android:id="@+id/messagesdetails_wrapLayout_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="start"
android:gravity="start"
android:background="@drawable/messages_item_background">
<TextView
android:id="@+id/messagesdetails_textview_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="15sp"
android:fontFamily="@font/segoe_ui"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:text="Your text" />
<TextView
android:id="@+id/messagesdetails_timestamp_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_gravity="start|bottom"
android:textSize="11dp"
android:fontFamily="@font/segoe_ui"
android:textColor="#80FFFFFF"
android:text="Timestamp" />
</androidx.appcompat.widget.LinearLayoutCompat>
<ImageView
android:id="@+id/messagesdetails_copybutton_right"
android:layout_width="28dp"
android:layout_height="28dp"
android:clickable="true"
android:alpha="1"
android:src="@drawable/copy_icon_messages_clicked" />
</LinearLayout>
>Solution :
To pin the view to the left in a constraint layout you can use the
app:layout_constraintHorizontal_bias="0"
See detailed answer. That way you can have constraints with left and right but the view would stick to the left.