您的位置:首页 > 其它

TextView下划线的添加,控制下划线和文字的距离

2018-02-28 16:01 357 查看

下面是效果图:

图片:

因为在思考这个效果的时候花了一点时间,所以记录了这个过程:首先实现上面效果我们首先会想到是什么?没错就是TextView的自带的下划线的属性:
holder.tvCount.setPaintFlags(Paint. UNDERLINE_TEXT_FLAG);
holder.tvCount.getPaint().setAntiAlias(true);//这里要加抗锯齿
1
2
不过这个实现的是下划线贴在文字的下面,效果不是很好,一般设计师大人也不会这么设计。
然后我想到在下面添加一个横线不就好了,不过多番尝试后发现下划线无法跟随上面文字长短变化,这里要怎么简单处理?这里思考,想让下面的线和上面长短变化相同,怎么做比较简单?聪明的你应该已经想到了,就是在下面在放一个TextView不就好了,然后也设置和上面一样的文字给它,他们不就一样了

补充

下面是同学留言说的方法,可以实现上述效果,感谢赐教。
下面是代码:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />

<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_alignBottom="@+id/tv_count"
android:layout_alignEnd="@+id/tv_count"
android:layout_alignStart="@+id/tv_count"
android:background="@color/colorAccent"
android:minWidth="4dp" />

</RelativeLayout>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
结束
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: