我正在尝试使用 drawable 向 View 添加笔画。 但我只想在侧面部分(左侧和右侧)添加它,而不是整个部分。 有没有什么好的方法可以在侧面部分添加描边?
下面是我的可绘制 xml 代码。 (leanear_border_gray.xml)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#778899"/>
</shape>
下面是我的目标 View xml 代码。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/linear_border_gray"
android:layout_weight="1">
....
</LinearLayout>
最佳答案
您需要将您的 shape
包装到具有矩形形状的 layer-list
drawable
中,添加描边并使用负值的顶部和底部边距“隐藏”顶线和底线,像这样:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-4dp" android:bottom="-4dp">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="#778899"/>
</shape>
</item>
</layer-list>
关于android - 我想在 View 中添加笔画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50717693/