android图片旋转
A. android怎么实现图片旋转
可以使用RotateAnimation动画实现,设定无限循环即可
代码如下
java">{
ImageViewiv;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
iv=(ImageView)findViewById(R.id.image);
RotateAnimationanimation=newRotateAnimation(0,360);
animation.setDuration(100000);//设定转一圈的时间
animation.setRepeatCount(Animation.INFINITE);//设定无限循环
animation.setRepeatMode(Animation.RESTART);
iv.startAnimation(animation);
}
}
也可以自定义view继承于imageview,启动一个线程,在while循环里设置view的旋转角度
{
privatefloatmCurDegree=0;//当前旋转角度
publicRotateView(Contextcontext,AttributeSetattrs){
super(context,attrs);
newThread(this).start();
}
@Override
protectedvoidonLayout(booleanchanged,intleft,inttop,intright,
intbottom){
super.onLayout(changed,left,top,right,bottom);
//设定旋转中心
setPivotX(getMeasuredWidth()/2);
setPivotY(getMeasuredHeight()/2);
}
@Override
publicvoidrun(){
while(true){
setRotation(mCurDegree);
mCurDegree+=5;
postInvalidate();
SystemClock.sleep(16);
}
}
}
在布局文件里使用RotateView代替imageview即可
B. android怎么实现一张图片旋转几秒后后自动换到另一张图片
图片旋转使用动画,设置动画时间,旋转完成后,设置另一张图片
RotateAnimation 动画,
RotateAnimation (float fromDegrees, float toDegrees, int
pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int
pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float
pivotXValue:X坐标的伸缩值。
int
pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float
pivotYValue:Y坐标的伸缩值。
C. 在android中,某图片使用rotateanimation动画,如何绕着这个图片的左下角的进行旋转
1、定义一个ImageView
定义一个ImageView是为了装载图片,其中的图片将被rotate用来进行旋转,其他View亦可。
资源文件为
复制代码代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/infoOperating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/operating"
android:scaleType="center">
</ImageView>
</LinearLayout>
其中的android:src为图片内容,可使用附件中的图片。
java代码为
复制代码代码如下:
ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating);
2、定义rotate旋转效果
在res/anim文件夹下新建tip.xml文件,内容如下
复制代码代码如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:ration="500"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%" />
</set>
含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。
java代码为
复制代码代码如下:
Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);
setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。
a. 关于其中的属性意义如下(红色部分加以注意):
android:fromDegrees 起始的角度度数
android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针。如10圈则比android:fromDegrees大3600即可
android:pivotX 旋转中心的X坐标
浮点数或是百分比。浮点数表示相对于Object的左边缘,如5; 百分比表示相对于Object的左边缘,如5%; 另一种百分比表示相对于父容器的左边缘,如5%p; 一般设置为50%表示在Object中心
android:pivotY 旋转中心的Y坐标
浮点数或是百分比。浮点数表示相对于Object的上边缘,如5; 百分比表示相对于Object的上边缘,如5%; 另一种百分比表示相对于父容器的上边缘,如5%p; 一般设置为50%表示在Object中心
android:ration 表示从android:fromDegrees转动到android:toDegrees所花费的时间,单位为毫秒。可以用来计算速度。
android:interpolator表示变化率,但不是运行速度。一个插补属性,可以将动画效果设置为加速,减速,反复,反弹等。默认为开始和结束慢中间快,
android:startOffset 在调用start函数之后等待开始运行的时间,单位为毫秒,若为10,表示10ms后开始运行
android:repeatCount 重复的次数,默认为0,必须是int,可以为-1表示不停止
android:repeatMode 重复的模式,默认为restart,即重头开始重新运行,可以为reverse即从结束开始向前重新运行。在android:repeatCount大于0或为infinite时生效
android:detachWallpaper 表示是否在壁纸上运行
android:zAdjustment 表示被animated的内容在运行时在z轴上的位置,默认为normal。
normal保持内容当前的z轴顺序
top运行时在最顶层显示
bottom运行时在最底层显示
b. 运行速度
运行速度为运行时间(android:ration)除以运行角度差(android:toDegrees-android:fromDegrees),比如android:ration为1000,android:toDegrees为360,android:fromDegrees为0就表示1秒转1圈。
c. 循环运行
复制代码代码如下:
android:fromDegrees="0"
android:toDegrees="360"
android:repeatCount="-1"
android:repeatCount="-1"即表示循环运行,配合上android:fromDegrees="0" android:toDegrees="360"表示不间断
3、开始和停止旋转
在操作开始之前调用
复制代码代码如下:
if (operatingAnim != null) {
infoOperatingIV.startAnimation(operatingAnim);
}
在操作完成时调用
复制代码代码如下:
infoOperatingIV.clearAnimation();
许多朋友不知道如何停止旋转animation,所以强制设置rotate转动多少圈表示操作,但却无法与操作实际的进度匹配上,实际上只要如上代码所示清除animation即可。
其他:
对于上面的转动在横屏(被设置为了不重绘activity)时会出现问题,即旋转中心偏移,导致动画旋转偏离原旋转中心。解决如下
复制代码代码如下:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (operatingAnim != null && infoOperatingIV != null && operatingAnim.hasStarted()) {
infoOperatingIV.clearAnimation();
infoOperatingIV.startAnimation(operatingAnim);
}
}
D. 安卓手机怎么镜面翻转
大部分图片处理软件就这样的功能,比如美图秀秀。
打开图片,选择编辑,选择旋转,选择镜面图标就可以了。
不过在编辑结束,最好选择另存为,而不是覆盖保存,这样原始图片就会被编辑过的覆盖,如果再用就比较麻烦。
E. android 怎么让图片实现朝Z轴的方向旋转RotateAnimation是x y方向的,我想要包含z方向的
RotateAnimation是不可以绕Z轴旋转的,如果LZ想要实现Z轴旋转效果,可以看下matrix这个类(实际还是opengl),可以给LZ例举下:
rotateX(float degree) 绕着x轴旋转degree个度数
rotateY(float degree) 绕着y轴旋转degree个度数
rotateZ(float degree) 绕着z轴旋转degree个度数
F. 如何让手机里的照片旋转
1、打开手机界面上面的“图库”选项
G. 手机照相的时候照片总是自己旋转,怎么办呢
手机照相的时候照片总是自己旋转,如果不想旋转,就把图库自动旋转按钮关闭就可以了,操作方法是;以华为手机为例:
1、首先在手机屏幕上,找到手机上的“图库”图标。
H. 安卓手机怎么设置图标旋转快慢
在手机自带设置中进行操作即可。
选择设置显示进入,打开自动旋转,或者是在通知中心中点击旋转的开关,只需将手机横过来,就自动变成了横屏状态。
android(安卓)通常是指手机操作系统,Android是一个开源的,基于Linux的移动设备操作系统,主要使用于移动设备,如智能手机和平板电脑。Android是由谷歌及其他公司带领的开放手机联盟开发的。在目前市场上,由于它的开源性,所以很多手机厂商研发手机时搭载Android操作系统,比如华为手机的EMUI是基于Android,还有小米、OPPO、魅族等大部分手机品牌都是使用Android。
I. 手机图片怎么镜像翻转
以iphone11、醒图为例,操作如下:
1、打开醒图应用,选择导入图片的选项。
J. android 中用画布旋转图片的时候怎么让让他 围着一个坐标旋转
方法只有一种。
步骤:
1、画布平移坐标原点
2、旋转画布
示例代码
canvas.save();//保存当前画布状态
canvas.translate(x,y);//将坐标中心平移到要围绕的坐标点x,y
canvas.rotate(90);//旋转角度,这里比如90度
canvas.restore();//恢复画图状态到保存前