android - 只有两侧的形状可绘制

标签 android

我正尝试在 XML 中实现像这样的 ShapeDrawable,但到目前为止没有成功。

enter image description here

如何使 Stroke 仅在两侧可见?

这可能吗?

否则我使用什么云(我将其作为 TextView 的背景)。

最佳答案

这是一个使用 LayerListDrawable 的解决方案:

background_white_lateral_border.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@android:color/white" />
        </shape>
    </item>

    <item>
        <inset
            android:insetLeft="1dp"
            android:insetRight="1dp" >
            <shape android:shape="rectangle" >
                <solid android:color="@android:color/black" />
            </shape>
        </inset>
    </item>

</layer-list>

注意:这首先绘制了一个白色矩形,然后绘制了一个黑色矩形,在其顶部左右插入了 1dp,给出了横向边框的效果。这只是要记住的事情,以防您担心性能(在我看来,对于像这样的小样式来说,性能可以忽略不计)。

关于android - 只有两侧的形状可绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19363327/

相关文章:

Android 日期选择器 - 实际日期减去 X 天数

java - 在 ListView 中显示 JSON 数据仅显示 Array 中的第一个元素

经典和 BTLE 设备的 Android 蓝牙扫描

android - 仅在应用程序升级时升级行

android - 现在,Youtube API的配额限制是多少?

Android - 查找当前是否正在播放音频并停止播放

android - 计算堆栈大小时,Android,gradle,Proguard错误:

android - 滑动菜单 Android

android - 包括 Room-library 会增加应用下载大小(~10mb)

android - Http 中断/parial 文件下载 - Android/iPhone 上的 HTTP "Range" header