I want to create a layout when I have an image, text aligned to the left of the layout. and a chip aligned to the left.
I have tried this layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/my_padding"
android:paddingBottom="@dimen/my_padding"
android:paddingLeft="@dimen/my_padding2"
android:paddingRight="@dimen/my_padding2"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal">
<ImageView
android:id="@+id/Icon"
android:layout_width="@dimen/icon_size"
android:layout_height="@dimen/icon_size"
android:layout_margin="@dimen/icon_margin"
android:layout_gravity="center_horizontal|center_vertical"
android:contentDescription="@null"
android:importantForAccessibility="no"
tools:ignore="UnusedAttribute" />
<TextView
android:id="@+id/Text"
style="@style/ActionItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_between_icon_and_text"
android:layout_marginLeft="@dimen/margin_between_icon_and_text"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="3"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<com.my.Chip
android:id="@+id/highlight_chip"
style="@style/Widget.Chip.Suggestive"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_between_highlight_chip_and_text"
android:layout_marginLeft="@dimen/margin_between_highlight_chip_and_text"
android:layout_gravity="end|center_vertical"
android:visibility="visible" />
</LinearLayout>
Why does the textView's match_parent makes the chip's width to be 0dp?
I read about match_parent:
Special value for the height or width requested by a View. MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. Introduced in API Level 8.
but does it ignores the siblings size?
I know I can use weight
, but still want to understand: does match_parent
ignore siblings' width?