【发布时间】:2019-09-24 08:05:18
【问题描述】:
当我有一个图像时,我想创建一个布局,文本与布局的左侧对齐。 和一个向左对齐的芯片。
我试过这个布局:
<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="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
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>
意思是我有带有重量和layout_gravity的芯片,但是没有看到芯片。
我该如何解决这个问题?
奇怪的是我试过了
<com.my.Chip
android:id="@+id/highlight_chip"
style="@style/Widget.GoogleMaterial.Chip.Suggestive"
android:layout_width="10dp"
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" />
没有重量,芯片仍然不显示
【问题讨论】:
-
为什么要坚持线性布局?
标签: android android-layout android-linearlayout android-layout-weight