我如何指定背景色的是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 和安卓endColor
you can specify the angle by replacing the android:angle
value and start/end colour by replacing android:startColor
and android:endColor