[英]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.