View Full Version : انیمیشن برای چرخاندن یک عکس به دور خودش و یا حرکت در محور X یا Y
id1385
پنج شنبه 16 مرداد 1393, 00:07 صبح
سلام
دوستان من دنبال یک انیمیشن xml میگردم بدون اینکه با کد بخواهیم اونو فراخونی کنیم و استارتش کنیم یک عکس رو بدور خودش مثل لودینگ یا در محور X یا محور Y حرکت بدیم
بدون اینکه نیاز به دیوریشن باشه یعنی لوپ باشه بصورت پیش فرض.
ممنون میشم اگه اساتید کمک کنن
akbar8298
پنج شنبه 16 مرداد 1393, 10:13 صبح
من برای این کار تصویرم رو فریم فریم کردم.
فایلشو براتون میزارم122063
id1385
پنج شنبه 16 مرداد 1393, 12:30 عصر
من برای این کار تصویرم رو فریم فریم کردم.
فایلشو براتون میزارم122063
با تشکر از دوست عزیزم
از اینکه زحمت کشیدید و جواب دادید ممنونم، منتها من نمیخوام فریمهای عکسو بیارم در اصل من یک shape ایجاد کردک کیخوام اونو دور خودش بچرخونم یا در محور x - y حرکتش بدم.
smemamian
پنج شنبه 16 مرداد 1393, 13:44 عصر
سلام
باید کلاسی بسازید که از ImageView مشتق شده باشد:
public class RotateImageView extends ImageView {
private static Animation mRotation;
public boolean isAnimating = false;
public RotateImageView(Context context) {
super(context);
Init(null);
}
public RotateImageView(Context context, AttributeSet attrs) {
super(context, attrs);
Init(attrs);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public RotateImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Init(attrs);
}
private void Init(AttributeSet attrs) {
startAnimation();
}
public void startAnimation() {
if(!isAnimating){
if (mRotation == null) {
mRotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
mRotation.setRepeatCount(Animation.INFINITE);
}
this.startAnimation(mRotation);
isAnimating = true;
}
}
public void stopAnimation() {
if (isAnimating){
mRotation.cancel();
isAnimating = false;
}
}
@Override
public void setVisibility(int visibility) {
if (visibility == GONE || visibility == INVISIBLE) {
this.clearAnimation();
} else if (visibility == VISIBLE) {
this.startAnimation(mRotation);
}
super.setVisibility(visibility);
}
}
سپس در پوشه anim یک فامیل xml به نام rotate بسازید:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:toDegrees="360" />
سپس در فایل xml :
<yourpackage.RotateImageView
android:id="@+id/yourid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/yourimage"
/>
سپس هرجا خواستید :
private static RotateImageView rotateimageview
rotateimageview = new RotateImageView(getActivity());
rotateimageview.stopAnimation();
or
rotateimageview.startAnimation();
نکته: در Fragmentها باید از getActivity استفاده کنید و در Activityها از this یا getApplicationContext .
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.