我想为linearLayout创建一个边框。所以我决定创建一个形状。我希望边框有一个渐变。下面的代码不是这样做的。它填充矩形,然后创建一个笔划。我不想要填充的矩形,只想要笔触。我想把渐变应用到笔划上。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="360"
android:centerColor="#e95a22"
android:endColor="#ff00b5"
android:gradientRadius="360"
android:startColor="#006386"
android:type="sweep" />
<stroke
android:width="2dp"
android:color="#ff207d94" />
</shape>
发布于 2014-01-02 00:59:49
尝试如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="360"
android:centerColor="#e95a22"
android:endColor="#ff00b5"
android:gradientRadius="360"
android:startColor="#006386"
android:type="sweep" />
<stroke
android:width="2dp"
android:color="#ff207d94" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle" >
<solid android:color="#fff" />
</shape>
</item>
</layer-list>
发布于 2017-11-17 17:47:24
由于被接受的答案并不完全像我希望的那样对我有效,我也会发布我的解决方案,也许它对其他人有帮助:)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<!-- create gradient you want to use with the angle you want to use -->
<shape android:shape="rectangle" >
<gradient
android:angle="0"
android:centerColor="@android:color/holo_blue_bright"
android:endColor="@android:color/holo_red_light"
android:startColor="@android:color/holo_green_light" />
</shape>
</item>
<!-- create the stroke for top, left, bottom and right with the dp you want -->
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle" >
<!-- fill the inside in the color you want (could also be a gradient again if you want to, just change solid to gradient and enter angle, start, maybe center, and end color) -->
<solid android:color="#fff" />
</shape>
</item>
</layer-list>
发布于 2016-05-31 22:34:13
这将创建一个顶部边框为2dp的布局。只需将其设置为布局的背景
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#4fc949"
android:centerColor="#0c87c5"
android:endColor="#b4ec51"
android:angle="180" />
</shape>
</item>
<item android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="@color/background_color"/>
</shape>
</item>
</layer-list>
https://stackoverflow.com/questions/20870853
复制相似问题