当前位置:   article > 正文

Android背景Shape颜色渐变—线性渐变_android 渐变

android 渐变

Android背景颜色渐变可以通过在res/drawable里定义一个xml文件(xml文件名称可根据个人定义):

一、color_gradient.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. <gradient
  5. android:angle="0"
  6. android:startColor="#95C5F3"
  7. android:centerColor="#FFFFFF"
  8. android:endColor="#9BDD52"
  9. android:type="linear"/>
  10. </shape>
1、android:angle 渐变方向角度
2、android:startColor 开始颜色
3、android:centerColor 中间颜色
4、android:endColor 结束颜色
5、android:type 渐变类型,线性linear

二、在你想要实现的界面中使用:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".ColorActivity"
  8. android:orientation="vertical"
  9. android:background="@drawable/color_gradient">
  10. </LinearLayout>

三、效果图:

1、android:angle=0,从左到右,颜色按照开始颜色(startColor)到结束颜色(endColor),(angle=360的效果与angle=0是一样的);

2、android:angle=45,从左下角到右上角,颜色按照开始颜色(startColor)到结束颜色(endColor);

3、android:angle=90,从下到上,颜色按照开始颜色(startColor)到结束颜色(endColor);
4、android:angle=135,从右下角到左上角,颜色按照开始颜色(startColor)到结束颜色(endColor);

5、android:angle=180,从右到左,颜色按照开始颜色(startColor)到结束颜色(endColor);

6、android:angle=225,从右上角到左下角,颜色按照开始颜色(startColor)到结束颜色(endColor);

7、android:angle=270,从上到下,颜色按照开始颜色(startColor)到结束颜色(endColor);
8、android:angle=315,从左上角到右下角,颜色按照开始颜色(startColor)到结束颜色(endColor);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/420616
推荐阅读
相关标签
  

闽ICP备14008679号