Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

View gets pushed out of linear layout – android

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading