视图的边框纹理

3
有没有办法为LinearLayout或其他View设置边框纹理?我无法仅设置图像作为背景,因为不同屏幕大小会导致问题。这是我所说的纹理的样本: https://istack.dev59.com/PkaYt.webp。我尝试使用Nine-Patch,但它会拉伸应该重复的白线。来自Draw 9-patch工具的截图: https://istack.dev59.com/ApqYo.webp。
1个回答

5
您可以像这样使用shape drawable:
<shape android:shape="rectangle">
    <solid android:color="#FAFAD2" />           
    <stroke android:width="1sp" android:color="#000000"
        android:dashWidth="7sp" android:dashGap="5sp" />
</shape>

这将会得到类似于这样的结果:

在此输入图片描述

您可以根据自己的需求更改颜色、宽度、边框等。


我不需要纯色作为背景。它必须是我上面链接的样本中的深色纹理。 - Roman
然后按照您的需求进行制作。这是那个问题唯一优雅的解决方案。 - Octavian Helm
但是能否将纹理设置为形状背景呢?或者至少让它透明? - Roman
1
太好了!我设置了 <solid android:color="#00000000" />,它起作用了。谢谢。在这里找到了答案 - https://dev59.com/zG035IYBdhLWcg3wErrM - Roman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接