2016-04-22 104 views
0

我定義了一個可繪製的形狀,它是一條線。TextView無法設置DrawableLeft(或頂部,右側,底部)與形狀可繪製?

<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" /> 

爲什麼以及如何讓它工作?

+0

你嘗試在你的形狀中爲筆畫設置一個'android:height'屬性嗎? – SlashG

+0

中風沒有'android:height'屬性 – idengpan

回答

3

試試這個!!!!

<?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> 
0

一個解決方案是在textview下面添加一個單獨的視圖。既然你只是想要一條線添加一個視圖,並設置高度爲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> 
+0

我知道這個解決方案,但不想使用它。謝謝! – idengpan

+0

@idengpan lol:D –

相關問題