码迷,mamicode.com
首页 > 其他好文 > 详细

圆角边框和渐变

时间:2015-07-23 23:24:16      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

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

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

 

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

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

 

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

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     tools:context=".MainActivity">
 7 
 8     <!--通过background指定背景-->
 9     <TextView
10         android:layout_width="match_parent"
11         android:layout_height="wrap_content"
12         android:text="带边框的文本"
13         android:textSize="24sp"
14         android:background="@drawable/bg_border"/>
15     <TextView
16         android:layout_width="match_parent"
17         android:layout_height="wrap_content"
18         android:text="圆角边框,渐变背景的文本"
19         android:textSize="24sp"
20         android:background="@drawable/bg_border2"/>
21 
22 </LinearLayout>

 

圆角边框和渐变

标签:

原文地址:http://www.cnblogs.com/LY1124/p/4671980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!