我有一个垂直排列的LinearLayout,其中包含3个TextViews
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:textSize="@dimen/text_size_large"
android:text="Item1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:textSize="@dimen/text_size_large"
android:text="Item2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:textSize="@dimen/text_size_large"
android:text="Item3"/>
</LinearLayout>
我可以将可绘制对象应用于背景属性以呈现边框。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="@color/pale_grey" />
<padding android:left="24dp" android:right="24dp"
android:top="12dp" android:bottom="12dp" />
</shape>
</item>
</layer-list>
我还可以通过可绘制的选择器来应用选择器到背景属性,以便TextView根据按下等状态更改颜色。但是,只有一个背景属性。
我不认为我可以在同一个可绘制对象中应用 XML和 XML。因此,我需要将单个布局元素包装在每个TextView周围,以便可以应用另一个背景吗?
看起来谷歌通过将边框、填充和背景颜色合并到一个可绘制的patch-9图像中来解决了这个问题。我希望我不需要那样做。
谢谢