设置布局视图的背景色在Android的梯度? [英] Set the background colour of a Layout view to a gradient in Android?
本文介绍了设置布局视图的背景色在Android的梯度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何指定背景色的是Android布局视图元素应该是一个梯度(在一个特定的角度)?
How do I specify that the background "colour" of a Android layout view element should be a gradient (at a specific angle) ?
我要在XML指定此,即不是在运行时。 preferably作为一种风格,我可以申请我希望与风格
财产的布局?
I wish to specify this in the XML, i.e. not at runtime. Preferably as a style I can apply to any layout I wish with the style
property?
推荐答案
创建 gradient.xml
在 / RES /绘制
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFFFF"
android:endColor="#00000000"
android:angle="45"/>
</shape>
和您的的main.xml
布局文件中的 / RES /布局
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gradient"
>
</LinearLayout>
通过替换 Android的角度
值和开始/结束颜色:startColor 您可以通过替换 Android的指定角>和
安卓endColor
you can specify the angle by replacing the android:angle
value and start/end colour by replacing android:startColor
and android:endColor
这篇关于设置布局视图的背景色在Android的梯度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文