5

Tôi mới sử dụng android, chỉ cần hỏi một câu hỏi đơn giản, làm cách nào để thêm dòng dưới cùng vào chế độ xem văn bản nó xuất hiện ở dưới cùng của tế bào như 1dp, đây là mã cho đến nay:Làm cách nào để thêm dòng 1dp vào cuối ô xem văn bản của tôi (không phải bố cục bảng)

<?xml version="1.0" encoding="UTF-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="47.5dp" 
     android:layout_marginLeft="2dp" 
     android:layout_marginRight="2dp" 
     android:paddingTop="13dp" 
     android:background="@drawable/line_str" 
     android:paddingLeft="8dp" 
     android:text="@string/manage_categories" 
     android:singleLine="true" 
     android:textColor="@color/white" 
     android:fontFamily="Roboto-Regular" 
     android:layout_gravity="center" 
     android:textSize="16sp" 
     /> 

line_str.xml như sau:

<?xml version="1.0" encoding="utf-8"?> 


<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- This is the main color --> 
<item> 
    <shape> 
     <solid android:color="@color/black" /> 
    </shape> 
</item> 
<!-- This is the line --> 
<item android:bottom="1dp"> 
<shape> 
     <solid android:color="#252525" /> 
</shape> 
</item> 
</layer-list> 

Bất kỳ trợ giúp đánh giá cao. Cảm ơn!

Trả lời

6

Tôi muốn đặt hình ảnh 9patch mở rộng theo chiều ngang và thêm nó vào thuộc tính drawableBottom của chế độ xem văn bản.

Đối với các cách tiếp cận lớp-list thử điều này:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- This is the main color --> 
<item> 
    <shape> 
     <size android:height="@dimen/textViewHeight"/> 
     <solid android:color="@color/black" /> 
    </shape> 
</item> 
<!-- This is the line --> 
<item android:top="@dimen/textViewHeight"> 
<shape> 
     <size android:height="1dp"/> 
     <solid android:color="#252525" /> 
</shape> 
</item> 
</layer-list> 
+0

@ dimen/textviewheight là gì? –

+1

đây sẽ là tuyên bố của bạn về chiều cao của textView trong thư mục dimens.xml. Hoặc bạn có thể mã hóa giá trị ngay tại đây. –