2016-04-22 7 views
0

Ich habe eine Form definiert, es ist eine Linie.TextView kann DrawableLeft (oder Top, Right, Bottom) nicht mit Shape-Zeichen festlegen?

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="line" > 
<stroke android:color="#f00" android:width="2dp"/> 
</shape> 

und dann habe ich diese Form in TextView DrawableBottom, aber es hat nicht funktioniert.

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

warum und wie kann es funktionieren?

+0

Haben Sie versucht, ein Attribut "android: height" für den Strich in Ihrer Form zu setzen? – SlashG

+0

Schlaganfall habe nicht 'Android: Höhe' Attribut – idengpan

Antwort

3

Try this !!!!

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

Eine Lösung besteht darin, nur eine separate Ansicht unterhalb der Textansicht hinzuzufügen. Da Sie nur eine Zeile hinzufügen anzeigen möchten, und stellen Sie die Höhe 2dp und die Hintergrundfarbe auf # 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

Ich kenne diese Lösung, aber ich möchte sie nicht verwenden. Vielen Dank! – idengpan

+0

@idengspan lol: D –