利用layer-list和shape实现下划线效果

简介: 因为shape如果形状设为line,则是居中的,可以做分割线,但是无法做下划线。比如我们想为TextView设置一个背景,实现下划线。需要用layer-list,因为shape的stroke是四周描边的,这里android:left="-4dp"就是指item的drawable(就是shape)从整个画布的-4dp开始绘制,这样其实显示在画布中的shape就没有左边了,同理,上左右都这么处理就只剩下底边,就实现了下划线效果


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:left="-4dp"
        android:right="-4dp"
        android:top="-4dp">
        <shape>
            <solid android:color="#00FFFFFF" />
            <stroke
                android:width="2dp"
                android:color="#ebedfb" />
        </shape>
    </item>
</layer-list>
复制代码


因为shape如果形状设为line,则是居中的,可以做分割线,但是无法做下划线。

比如我们想为TextView设置一个背景,实现下划线。

需要用layer-list,因为shape的stroke是四周描边的,这里android:left="-4dp"就是指item的drawable(就是shape)从整个画布的-4dp开始绘制,

这样其实显示在画布中的shape就没有左边了,同理,上左右都这么处理就只剩下底边,就实现了下划线效果

目录
相关文章
|
11天前
|
算法
shape_predictor
【6月更文挑战第19天】
15 8
|
8天前
|
机器学习/深度学习 算法 图形学
shape_predictor_68_face_landmarks
【6月更文挑战第22天】
21 7
|
20天前
|
计算机视觉 Python
shape
【6月更文挑战第10天】
8 0
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
677 0
解决AssertionError: size of input tensor and input format are different.tensor shape: (3, 138input_for
解决AssertionError: size of input tensor and input format are different.tensor shape: (3, 138input_for
344 0
|
Python
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
714 0
|
计算机视觉
'cv2' has no attribute '_registerMatType 问题解决
'cv2' has no attribute '_registerMatType 问题解决
4073 0
成功解决ValueError: Cannot feed value of shape (1, 10, 4) for Tensor Placeholder:0 , which has shape
成功解决ValueError: Cannot feed value of shape (1, 10, 4) for Tensor Placeholder:0 , which has shape