如何从中心位置旋转imageview

时间:2013-12-16 10:05:05

标签: java android android-layout

我想将Imageview从中心位置移开。 imageview的一边超出此范围,之后imageview的另一边应该降下来 imageview的中心始终固定。怎么做我的代码是

imageView= (ImageView) findViewById(R.id.imageView1);

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            RotateAnimation animation = new RotateAnimation(80, 90, imageView.getWidth() / 2, 400);

            animation.setDuration(400); // you may  set another duration
            animation.setFillAfter(true);
            imageView.startAnimation(animation);

        }
    });
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="86dp"
    android:src="@drawable/top_pati" />
<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_below="@+id/imageView1"
    android:src="@drawable/top_pativertical" />
<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageView1"
    android:layout_below="@+id/imageView1"
    android:src="@drawable/top_pativertical" />

像缩放类型一样 我做这项工作的动画类型......

4 个答案:

答案 0 :(得分:3)

使用此代码

RotateAnimation anim = new RotateAnimation(0, 45, Animation.RELATIVE_TO_SELF,
            0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

anim.setInterpolator(new LinearInterpolator());
anim.setDuration(500);
anim.setFillEnabled(true);
anim.setFillAfter(true);

image.startAnimation(anim)

答案 1 :(得分:2)

RotateAnimation anim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

anim.setInterpolator(new LinearInterpolator());
anim.setDuration(500);
anim.setFillEnabled(true);
anim.setFillAfter(true);

image.startAnimation(anim);

答案 2 :(得分:1)

Try this..
You can save this as xml file(image.xml) in res/drawable folder and where you want to rotate imageview then include this line android:src=@drawble/image.

<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%" 
android:fromDegrees="0"
android:toDegrees="360" 
android:drawable="@drawable/prgbar" />

答案 3 :(得分:0)

1-必须检查图像视图的宽度和高度,如果高度>宽度然后在旋转时宽度必须等于高度并且与高度相同。

2-使宽度和高度等于fill_parent,然后通过矩阵旋转/平移/缩放。