android渐变效果

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent" android:layout_height="500px"
android:text="Hello World!" android:background="@drawable/bg_border
"
android:textColor="#ffffff"/>
</LinearLayout>

drawable文件下建立bg_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 指定圆角矩形的4个圆角的半径 -->
<corners android:topLeftRadius="20px"
android:topRightRadius="5px"
android:bottomRightRadius="20px"
android:bottomLeftRadius="5px"/>
<!-- 指定边框线条的宽度和颜色 -->
<stroke android:width="4px" android:color="#f0f" />
<!-- 指定使用渐变背景色,使用sweep类型的渐变
颜色从红色→绿色→蓝色 -->
<gradient android:startColor="#f00"
android:centerColor="#0f0"
android:endColor="#00f"
android:angle="270"
android:centerX="0.5"
android:centerY="0.5"
/>
<!--angle的值:从左到右为0;然后逆时针旋转,90度为从下到上,270为从上到下。
centerx和centery的值取0-1;表示中间色的位置,中间色分别是0,0.5,1。中间色为0的,则渐变的中间色的位置在最上面;中间色为0.5的,则渐变的中间色在屏幕中间;中间色为1 的,则中间色在屏幕下部。-->
</shape>
运行结果:

<gradient android:startColor="#f00"
android:centerColor="#0f0"
android:endColor="#00f"
android:angle="90"
android:centerX="0.5"
android:centerY="0.5"
/>


posted @ 2015-09-29 21:01  冰凝夢  阅读(4630)  评论(0编辑  收藏  举报