当我有图像时,我想创建一个布局,文本与布局的左侧对齐。芯片向左对齐。
我尝试过这种布局:
<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>
为什么textView的match_parent使芯片的宽度为0dp?
我读到match_parent:
视图所要求的高度或宽度的特殊值。MATCH_PARENT表示该视图希望与其父视图一样大,减去父母的填充物(如果有)。在API级别8中引入。
但是它会忽略兄弟姐妹的大小吗?
我知道我可以使用weight
,但仍然想了解:match_parent
是否忽略兄弟姐妹的宽度?
match_parent
属性根据父视图做出反应。 LinearLayout
的子视图的宽度为`match_parent,它将占据整个宽度,并且如果在我们谈论abour宽度时方向是水平的,则将不容纳任何其他子视图。