Android 旋转渐变而不是椭圆
我有一个带有扫描渐变的椭圆形,我想旋转渐变而不是椭圆形本身(因为当我旋转椭圆形时,它不再处于正确的位置)。我找不到关于这个的任何东西。有什么想法吗?这就是我想做的Android 旋转渐变而不是椭圆,android,android-layout,rotation,gradient,Android,Android Layout,Rotation,Gradient,我有一个带有扫描渐变的椭圆形,我想旋转渐变而不是椭圆形本身(因为当我旋转椭圆形时,它不再处于正确的位置)。我找不到关于这个的任何东西。有什么想法吗?这就是我想做的 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape xmlns:an
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#585858" />
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="40">
<gradient
android:endColor="#FF7DD6"
android:startColor="#FFFFFF"
android:type="sweep"
android:useLevel="false" />
</rotate>
</shape>
</item>
</layer-list>
gradient
有一个属性angle
,它接受一个int值来为渐变指定方向
根据报告:
渐变的角度,以度为单位。0表示从左到右,90表示从下到上它必须是45的倍数。默认值为0
通过改变角度,可以旋转渐变
例如:
<gradient
android:endColor="#FF7DD6"
android:startColor="#FFFFFF"
android:type="sweep"
android:angle="270"
android:useLevel="false" />
gradient
有一个属性angle
,它接受一个int值来为渐变指定方向
根据报告:
渐变的角度,以度为单位。0表示从左到右,90表示从下到上它必须是45的倍数。默认值为0
通过改变角度,可以旋转渐变
例如:
<gradient
android:endColor="#FF7DD6"
android:startColor="#FFFFFF"
android:type="sweep"
android:angle="270"
android:useLevel="false" />
如果您使用的是SweepGradient,则可以使用setLocalMatrix方法:
float initial_rotation_angle_degrees = 30;
SweepGradient gradient = new SweepGradient(0,0
,new int[]{
,0xff0078be
,0xfff4535c
}
,null);
Matrix matrix = new Matrix();
// Rotating the gradient
matrix.postRotate(initial_rotation_angle_degrees);
// Translating the gradient (The initial cx, cy values must be 0)
matrix.postTranslate(cx,cy);
gradient.setLocalMatrix(matrix);
如果您使用的是SweepGradient,则可以使用setLocalMatrix方法:
float initial_rotation_angle_degrees = 30;
SweepGradient gradient = new SweepGradient(0,0
,new int[]{
,0xff0078be
,0xfff4535c
}
,null);
Matrix matrix = new Matrix();
// Rotating the gradient
matrix.postRotate(initial_rotation_angle_degrees);
// Translating the gradient (The initial cx, cy values must be 0)
matrix.postTranslate(cx,cy);
gradient.setLocalMatrix(matrix);
谢谢你的回复。不幸的是,这不适用于扫描梯度,但它适用于线性梯度道歉@cagdas,我最初没有注意到它是扫描。谢谢你的回复。不幸的是,这不适用于扫描梯度,但适用于线性梯度。抱歉@cagdas,我最初没有注意到这是一个扫描。该方法
postRotate(float degrees,float px,float py)
也很有用。它将根据px
和py
方法postRotate(浮动角度、浮动px、浮动py)进行旋转
。它将根据px
和py