PDA

View Full Version : مشکل با انیمیشن در xml



r.miri19
شنبه 06 تیر 1394, 01:25 صبح
من در برنامه ای که دارم می سازم .می خوام یک عکس هر 2 ثانیه یک بار روشن و خاموش بشه.این کد رو دادم تو فایل xml
اما مشکل داره ، یه بار دزست کار می کنه ، یه بار روشن که می شه می مونه و نظم نداره
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >

<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:startOffset="1000"
android:toAlpha="1.0" />
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:startOffset="2000"
android:toAlpha="0.0" />

</set>

tux-world
شنبه 06 تیر 1394, 09:49 صبح
از این کد استفاده کن. نمونه هستش

public void onCreate(Bundle savedInstanceState) {
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
final Button btn = (Button) findViewById(R.id.your_btn);
btn.startAnimation(animation);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
view.clearAnimation();
}
});
}

r.miri19
شنبه 06 تیر 1394, 15:25 عصر
از این کد استفاده کن. نمونه هستش

public void onCreate(Bundle savedInstanceState) {
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
final Button btn = (Button) findViewById(R.id.your_btn);
btn.startAnimation(animation);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
view.clearAnimation();
}
});
}

ممنون ک پاسخ دادید، یه سوال دیگه اگه من بخوام هر 10 ثانیه یک بار توی 1 ثانیه روشن ، خاموش بشه چطور میشه؟

tux-world
شنبه 06 تیر 1394, 16:25 عصر
متوجه نشدم منظورت چیه

r.miri19
شنبه 06 تیر 1394, 17:08 عصر
متوجه نشدم منظورت چیه

یک عکس دارم
هر 10 ثانیه که گذشت
روشن خاموش بشه.

r.miri19
یک شنبه 07 تیر 1394, 15:48 عصر
حل نشد.:گریه:

r.miri19
یک شنبه 07 تیر 1394, 23:55 عصر
کسی دیگه بلد نیست؟

tux-world
دوشنبه 08 تیر 1394, 09:54 صبح
یک عکس دارم
هر 10 ثانیه که گذشت
روشن خاموش بشه.

خوب کدی که دادم رو داخل TimerTask و یا CountDown بزاری یه خورده باهاش ور بری درست میشه:لبخندساده: