我有一个要求,我有一个ImageView的和一个按钮。
I have a requirement where I have an ImageView and a button.
的https://m.xsw88.com/allimgs/daicuo/20230906/2934.png
我要旋转图像,当我按一下按钮。我需要全屏幕上的图像。但是当我点击该按钮,图像会旋转,但在全屏幕不显示。请参阅下面的链接。
I want to rotate the image when I click the button. I need the image with full screen. but when I click the button image will be rotate, but not shown in the full screen. Please see the below link.
的https://m.xsw88.com/allimgs/daicuo/20230906/2935.png
在这之后还当我点击该按钮,图像旋转。但位置发生变化,而不是在全屏幕显示。
After that also when I clicked the button image will rotate. but positions is changed and not shown in full screen.
我的requrement是,当我点击该按钮,图像会roatate顺时针方向,将在全屏幕显示。我再次点击按钮图像必须旋转时钟明智和全屏幕显示。同样,当我按一下按钮图像必须旋转。
My requrement is, when I click the button image will be roatate clockwise and will show in full screen. Again I click the button image must be rotate clock wise and show in full screen. Likewise when I click the button image must be rotate.
因此,有人可以帮我吗?如果你可以给我一个样品code或将非常大大appriciated链接。
Therefore can someone help me? If you can give me a sample code or a link that will be very much appriciated.
下面是code,我正在努力,
Here is the code which I'm trying,
的main.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="@drawable/matterhorn"
/>
<Button
android:id="@+id/btnRotate"
android:layout_width="65dp"
android:layout_height="35dp"
android:layout_gravity="bottom|left"
android:layout_marginLeft="190dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/btn_icon_rotate"
>
</Button>
</merge>
这是我的主要活动MainActivity.java
package com.imageview.rotate;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Matrix;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class MainActivity extends Activity implements OnClickListener{
private Button btnRotate;
private ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgview = (ImageView) findViewById(R.id.imgView);
btnRotate = (Button) findViewById(R.id.btnRotate);
btnRotate.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnRotate:
Matrix matrix=new Matrix();
imgview.setScaleType(ScaleType.MATRIX); //required
matrix.postRotate((float) 180f, imgview.getDrawable().getBounds().width()/2, imgview.getDrawable().getBounds().height()/2);
imgview.setImageMatrix(matrix);
break;
}
}
}
在此先感谢。
Thanks in advance.
不错
创建 button_rotate.xml
在动画
文件夹:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
现在的Java文件中创建动画:
Now create animation in Java file:
/* Get ImageView Object */
ImageView iv = (ImageView) view.findViewById(R.id.refresh_action_view);
/* Create Animation */
Animation rotation = AnimationUtils.loadAnimation(context, R.anim.refresh_button_anim);
rotation.setRepeatCount(Animation.INFINITE);
/* start Animation */
iv.startAnimation(rotation);
有关停止动画:
iv.clearAnimation();
五月有用的这一个:
May Helpful this one:
投票最多;)
编码快乐:)保持旋转:)
Happy Coding :) Keep Rotating :)