TextView 不能设置 drawableLeft(或 Top、Right、Bottom)和 Shape drawable?
TextView can't set drawableLeft(or Top,Right,Bottom) with Shape drawable?
我定义了一个可绘制的形状,它是一条线。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke android:color="#f00" android:width="2dp"/>
</shape>
然后我在 TextView 的 drawableBottom 中设置了这个形状,但是没有用。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableBottom="@drawable/shape_line"
android:drawablePadding="5dip"
android:text="Hello World" />
为什么以及如何让它发挥作用?
一种解决方案是在文本视图下方添加一个单独的视图。因为你只想要一行添加一个视图并将高度设置为 2dp 并将背景颜色设置为#f00
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableBottom="@drawable/shape_line"
android:drawablePadding="5dip"
android:text="Hello World" />
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
//set your custom color
</View>
试试这个!!!!
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<size
android:height="1dp"
android:width="500dp" />
<solid android:color="#f00" />
</shape>
我定义了一个可绘制的形状,它是一条线。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke android:color="#f00" android:width="2dp"/>
</shape>
然后我在 TextView 的 drawableBottom 中设置了这个形状,但是没有用。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableBottom="@drawable/shape_line"
android:drawablePadding="5dip"
android:text="Hello World" />
为什么以及如何让它发挥作用?
一种解决方案是在文本视图下方添加一个单独的视图。因为你只想要一行添加一个视图并将高度设置为 2dp 并将背景颜色设置为#f00
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableBottom="@drawable/shape_line"
android:drawablePadding="5dip"
android:text="Hello World" />
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
//set your custom color
</View>
试试这个!!!!
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<size
android:height="1dp"
android:width="500dp" />
<solid android:color="#f00" />
</shape>