您的位置:首页 > 其它

圆角边框和渐变

2015-07-23 22:31 253 查看


Demo2\aa\src\main\res\drawable\bg_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--设置背景色为透明色-->
<solid android:color="#0000"/>
<!--设置红色边框-->
<stroke android:width="4dp" android:color="#f00"/>
</shape>


Demo2\aa\src\main\res\drawable\bg_border2.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--指定圆角矩形的4个圆角的半径-->
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="5dp" />
<!--指定边框线条的宽度和颜色-->
<stroke
android:width="4dp"
android:color="#f0f" />
<!--指定使用渐变背景色,使用sweep类型的渐变(红绿蓝)-->
<gradient
android:centerColor="#0f0"
android:endColor="#00f"
android:startColor="#f00"
android:type="sweep" />
</shape>


Demo2\aa\src\main\res\layout\activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<!--通过background指定背景-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="带边框的文本"
android:textSize="24sp"
android:background="@drawable/bg_border"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="圆角边框,渐变背景的文本"
android:textSize="24sp"
android:background="@drawable/bg_border2"/>

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: