2016-04-22 10 views
0

シェイプドローブを定義しました。これは線です。TextViewはShape DrawableでdrawableLeft(またはTop、Right、Bottom)を設定できませんか?

<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

解決策の1つは、テキストビューの下に別のビューを追加することです。行を表示し、高さを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 –

関連する問題