我堅持在Textview的末尾添加一個標籤。或者可能會在Textview的最後一段文字中出現邊框。如何邊框一塊TextView
諸如(熱,趨勢,..等等)的標籤必須位於標題的末尾。與冠軍同一條線上,如果有空間的背後,或新的生產線,如果不
請看下面的截圖
更新(上傳XML代碼)
bg_border_label_test.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<stroke
android:width="2dp"
android:color="#a30014" />
</shape>
item_post。 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16sp"
android:layout_marginRight="16sp">
<ImageView
android:id="@+id/imvPostImage"
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_marginTop="16sp"
android:background="#df7217"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/tvPostTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imvPostImage"
android:layout_marginLeft="16sp"
android:layout_toEndOf="@+id/imvPostImage"
android:layout_toRightOf="@+id/imvPostImage"
android:ellipsize="end"
android:ems="10"
android:lineSpacingExtra="-3dp"
android:maxLines="3"
android:textColor="#000"
android:textSize="16sp"
tools:text="Alan Walker vs Coldplay - Hymn For The Weekend" />
<TextView
android:id="@+id/tvPostLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tvPostTitle"
android:layout_alignParentRight="true"
android:background="@drawable/bg_border_label_test"
android:maxLines="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textColor="#a30014"
android:textSize="12sp"
android:textStyle="bold"
tools:text="HOT" />
<mgift.views.component.TextViewPlus
android:id="@+id/tvPublishDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imvPostImage"
android:layout_alignLeft="@+id/tvPostTitle"
android:maxLines="1"
android:textColor="@color/text_manatee"
android:textSize="@dimen/v4_small_size_text"
app:font="@string/open_sans_regular"
tools:text="3 hours ago" />
當前的結果:
期待的結果(標籤HOT稱號後總是)
謝謝你,但背景繪製不是我的問題。標籤必須位於標題的末尾。如果後面有空格,則與標題相同,否則換行。 –
您可以使用RelativeLayout作爲您的父級佈局,並添加一個元素,如android:layout_toRightOf =「@ + id/text_view_before_label」 – hsm59
如果TextView有2行,第一行填滿,第二行持續一半。標籤位置在哪裏? –