如何制作这样的形状?

3

我希望获得与下面所看到的形状类似的效果。我缺少的是标题颜色(匿名文本后面的颜色)。我通过将鼠标移动到第二个文本视图上来重现了我想要的效果,这样就可以突出显示并产生这种效果 :)

当前代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <stroke android:width="2dp" android:color="#000000" />
 <gradient android:startColor="#898989" android:endColor="#B5B5B5" android:angle="270"/> 

 <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
 android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape> 

enter image description here

3个回答

2
您需要使用包含两个可绘制对象的图层列表。举个例子,第一个将覆盖整个形状,而第二个将覆盖它,但设置了android:top="10dp",以创建显示底部第一个形状的偏移量。 编辑:
像这样:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <stroke
                android:width="2dp"
                android:color="#000000" />

            <solid android:color="#00ff00" />

            <corners
                android:bottomLeftRadius="7dp"
                android:bottomRightRadius="7dp" />
        </shape>
    </item>
    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="20dp">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="270"
                android:endColor="#B5B5B5"
                android:startColor="#898989" />

            <corners
                android:bottomLeftRadius="7dp"
                android:bottomRightRadius="7dp" />
        </shape>
    </item>
</layer-list>

谢谢,这似乎是一个更好的解决方案。 - c0dehunter
...但这并不完全OK - 现在整个标题周围都有描边了!是否可能仅将描边设置为左侧、顶部和右侧边框? - c0dehunter
没问题,我进行了编辑。 (从第二个形状中删除描边,并在偏移项中添加描边的大小) - eladr

1
使用LinearLayout,并将两个TextView放置在不同形状的背景下。
第一个具有圆角上角,第二个具有圆角下角。

0

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