在Android中创建渐变边界? [英] Create gradient border in android?

查看:1177
本文介绍了在Android中创建渐变边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个渐变边框像下面的图片吗?

How can I create a gradient border like in the image below?

推荐答案

您可以通过使用layerlist和填充搞乱实现这一目标。你需要3个要素:

You can achieve this by using a layerlist and messing with the padding. You'll need 3 elements:

1:border.xml形状,这仅仅是一个坚实的形状边框的颜色:border.xml

1: A border.xml shape, which is just a solid shape in the color of your border: border.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ff0000"/>
</shape>

2:内在的形状,在这里你想要的边框周围出现形状:inner.xml

2: The 'inner' shape, the shape where you want the border to appear around: inner.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00ff00"/>
</shape>

3:图层列表,它会把这2海誓山盟的顶部。您可以通过设置填充的内部形状创建边框:layerlist.xml

3: A layer list, which will put these 2 on top of eachother. You create the border by setting the padding on the inner shape: layerlist.xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/border"/>
<item android:drawable="@drawable/inner"

指定在这儿,你想有一个行程(前,左,右,下)

Specify here where you want to have a stroke(top, left, right, bottom)

android:top="3dp" android:right="0dp" android:bottom="3dp"
android:left="3dp" />

设置此为您的TextView的背景下,布局等。(要出现中风)

Set this as the background of your TextView, Layout etc. (where you want the stroke to appear)

或者只是创建 9Patch 图像的边界。

Or just create a 9Patch image with the borders.

这篇关于在Android中创建渐变边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆