我想创建一个这样的标签:
要求是:
我尝试的是为文本背景创建一个9ng图像,并使用padding属性作为红线的长度。通过覆盖onDraw方法绘制红线。
结果是红线是正确的但是背景被扩展,包括像这样的填充:
最好的方法是什么?构建包含标签的自定义视图?以编程方式100%绘制的自定义视图(在这种情况下,调整9ng图像大小的方法是什么?)?
由于 于连
答案 0 :(得分:1)
尝试这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The text"
android:textColor="#000000"
android:background="@drawable/<your_drawable>"
android:textSize="16sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#f00"
android:layout_weight="1" />
</LinearLayout>
希望它能帮到你
答案 1 :(得分:0)
最好的方法是使用两个不同的控制器。
您设置了一个简单的textView
,其矩形为背景,宽度设置为wrap-content
。
在此之后,您可以创建将她定位到所需位置的行(位于控制器右侧或页面末尾或您喜欢的位置),然后根据需要调整大小。
毫无疑问我在这里