res/drawable下新建一个myshapegradient.xml文件。代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
type="rectangle" >
<gradient
android:angle="90"
android:endColor="#000000"
android:startColor="#FFFFFF" />
</shape>
通过如下代码引用:
android:background="@drawable/myshapegradient"