android - 我想在视图中添加笔触
问题描述
我正在尝试使用drawable将笔画添加到视图中。但我只想将它添加到侧面部分(左右),而不是整个部分。有什么好的方法可以在侧面部分添加笔画吗?
下面是我的可绘制 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>
下面是我的目标视图 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>
推荐阅读
- python - OSError: [Errno 1] 不允许操作
- go - Go中使用递归和并发的第N个斐波那契数
- python - 在使用 keras Lambda 时,如何处理“TypeError: Object arrays are not supported”?
- python - Python 给了我索引号而不是列表中的输入。
- swift - 敏感数据的 Vapor 3 GET 路由
- rest - 为 NFL api 生成访问令牌
- java - Java,获取与输入部分匹配的模式部分
- java - servlet 中的 Beanutils 有问题
- r - 变异替换,如何指定为字符
- uwp - 似乎 UWP Async IO 仅在 10.0.17763 之后才是真正的异步操作,但在此之前不是真正的。怎么解释?