繁体   English   中英

如何从中心位置旋转imageview

[英]how to rotate imageview from its centre position

我想将Imageview从其中心位置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" />

像比例类型,我可以完成哪种类型的动画...

使用此代码

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)
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);
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" />

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM