2015-01-07 6 views
0

내가 이것을 달성하기 위해 노력하고있어 :Android : TextView에 줄을 추가하는 방법?

box

내가 아는 그 단지 라인이 솔루션 가능한대로 작동하는보기 아래의 텍스트 뷰를 constains 수직의 LinearLayout을 사용하여,하지만 난 좋겠 그것을 달성하기 위해 3 위젯을 사용하는 것을 좋아하지 않습니다. 내가 원하는 것은 TextView만을 사용하고 Drawable을 사용하여 선을 그리는 것입니다. 구현을 완료했지만 작동하지 않습니다 (선이 표시되지 않음). 내가 쓴 코드를 보자 :

<TextView 
    android:layout_width="100dp" 
    android:layout_height="150dp" 
    android:gravity="center" 
    android:text="Text" 
    android:drawableBottom="@drawable/line"/> 

line.xml 내 접근 방식을 사용하여 원하는 것을 얻을 수있다

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line"> 
    <stroke android:width="10dp" android:color="#3b50ec"/> 
</shape> 

경우, 사람이 내 코드에 문제가 있는지 알 수 있습니까?

답변

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="100dp" /> 

    <solid android:color="#3b50ec" /> 

</shape> 
+0

위대한 작품처럼 매력적입니다. 당신은 나의 영웅이다 :) – Androider

0

9 패치가 필요하다고 생각합니다. 여기에 (ab_transparent_dark_holo.9.png)는 SDK에서 하나의 :

enter image description here

그리고이 배경 속성으로 변경 : 문제는 당신 line.xml 파일에

<TextView 
    android:layout_width="100dp" 
    android:layout_height="150dp" 
    android:gravity="center" 
    android:text="Text" 
    android:background="@drawable/line"/> 
관련 문제