水平线背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="@color/colorAccent"
android:dashGap="4dp"
android:dashWidth="6dp"/>
</shape>
竖直虚线
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-600dp"
android:right="-600dp"> ---》 让其居中显示
<rotate android:drawable="@drawable/line_stroke"
android:visible="true"
android:fromDegrees="90"
/>
</item>
</layer-list>
引用
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layerType="software"
android:text="sss"
android:background="@drawable/line_vertical" />
本文介绍如何使用XML在Android应用中创建水平线和竖直线背景,包括虚线效果的实现方法。通过<shape>和<layer-list>元素,可以自定义线条的颜色、宽度、间隔等属性。
926

被折叠的 条评论
为什么被折叠?



