Android linearlaout layout_width does not work as expected

What is wrong with this xml? two text images do not seem to occupy the same space

           <LinearLayout
                android:id="@+id/detail_address" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:padding="10px"
                android:layout_weight="1">
                <TextView android:id="@+id/address" android:text="Address:"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical" android:textColor="@color/fontonbg"
                    android:gravity="right" android:layout_weight="1" />
                <TextView android:id="@+id/address_details"
                    android:text="Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:textColor="@color/bigfontonbg" android:textStyle="bold"
                    android:textSize="16sp" android:layout_toLeftOf="@+id/address_btn"
                    android:layout_marginLeft="10px" android:gravity="left"
                    android:layout_weight="1" android:layout_gravity="center_vertical" />
                <ImageView android:id="@+id/address_btn" android:src="@drawable/button"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginRight="10px" />
            </LinearLayout>
+3
source share
3 answers
android:layout_width="wrap_content"

This status tells Android that the view wants to be large enough to fit its own internal content, taking into account its own addition. This means that the width will depend on the length of the text in this TextView

+2
source

When you use android: layout_weight you should not use android:layout_width="wrap_content"but android:layout_width="0dp".

+2
source

android:orientation="vertical"

-2

Source: https://habr.com/ru/post/1791437/


All Articles