Android 如何定位径向梯度背景

Android 如何定位径向梯度背景,android,android-layout,background,gradient,Android,Android Layout,Background,Gradient,如何将径向渐变形状定位为线性布局中的背景?以下是我目前拥有的: 形状: <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:endColor="#e6e6e6" android:gradientRadius="800"

如何将径向渐变形状定位为线性布局中的背景?以下是我目前拥有的:

形状:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:endColor="#e6e6e6"
        android:gradientRadius="800"
        android:startColor="#fafaf9"
        android:type="radial"/>
</shape>

线性布局:

<?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/accueil_bg_gradient">
</LinearLayout>

我只想让渐变从屏幕的左上角开始,到右下角结束


非常感谢

将其设置为background mybackground.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle" android:layout_width="wrap_content">
            <stroke android:width="10dp" android:color="@color/darkBlue" />
            <solid android:color="#00000000" />
            <padding android:left="1dp" android:top="1dp" android:right="1dp"
                android:bottom="1dp" />
        </shape>
    </item>

    <item>
        <shape android:shape="rectangle">
            <gradient android:startColor="@color/grayBlue"
                android:endColor="@color/lightBlue" android:angle="270"
                android:centerColor="@color/lightBlue" />
            <!-- border width and color -->
            <stroke android:width="1dp" android:color="#FFDDDDDD" />
            <padding android:left="10dp" android:top="8dp" android:right="10dp"
                android:bottom="8dp" />
        </shape>
    </item>

</layer-list>

您可以使用渐变的“centerX”和“centerY”属性将径向渐变的中间移动到可绘制图形的不同位置。它们是介于0到1.0之间的浮点值,其中(相应地,centerX和centerY的值)0,0为左上角,1,1为右下角

默认值为0.5,0.5,这是可绘制/指定空间的中间位置。 例如,100px长(半径)的黑白渐变,其中间从左上角开始为:

    <shape android:shape="rectangle">
        <gradient
            android:type="radial"
            android:startColor="#ffffff"
            android:endColor="#000000"
            android:gradientRadius="100"
            android:angle="270"
            android:centerX="0"
            android:centerY="0"/>

    </shape>


如果你想改变渐变的角度,试着在元素中使用
android:angle
。谢谢你的回答,但这是一个径向渐变我,谢谢,但你给我的代码是线性渐变,但我希望有一个中心在左上角,末端在右下角的径向渐变