【发布时间】:2014-07-23 03:35:27
【问题描述】:
我有一个这样的 TextView:
<TextView
android:id="@+id/friends"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
我设置的背景是这样的:
textView.setBackgroundResource(R.drawable.background_color);
background_color.xml 在哪里:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#217dd2" />
</shape>
</item>
<item
android:left="5dip">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#deebf6" />
</shape>
</item>
这将删除我的默认填充 8dp 并将其替换为我在分层列表的第二项中声明的 5dp 的左侧填充。有什么办法可以避免这种情况?或者另一种为视图创建 2 色背景的方法?
【问题讨论】: