بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
ساخت یک Random Background
با سلام :
من می خواهم در یک Activity چند تا عکس بزارم به صورت بک گراند که هر چند ثانیه عوض بشود...ولی نمی دانم چطور این کار را انجام بدم...لطفا راهنمایی بفرمایید.
+1
0
از انیمشن باید استفاده کنی اگه خاستی بگو برات توضیح بدم (11 سال پیش)
0
0
ممنون میشم اگر کامل توضیح بدید .خیلی واجبه برام ... (11 سال پیش)
0
0
چشم الان براتون پست میکنم ولی یه دفعه برای یکی از کاربرا گذاشتم نمیدونم این سایت بود یا نه ولی باشه بازم میذارم یه چند دقیقه منتظر باشید (11 سال پیش)
برای این سوال 7 پاسخ وجود دارد.
پاسخ به سوال
mf2010
11 سال پیش
+2
0
اول تو اکتیوتی دلخواه یک imageView ایجاد میکنید مثل کد زیر
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
/>
خوب در پوشه drawble یه فایل به animation.xml میسازید مشخصه اول کد زیر نام عکس و دومی زمان نمایشش
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/background2" android:duration="3000" /> <item android:drawable="@drawable/background3" android:duration="3000" /> <item android:drawable="@drawable/background4" android:duration="3000" /> <item android:drawable="@drawable/background5" android:duration="3000" /> </animation-list>
خوب میریم سراغ سورس کد اول اون imageView رو معرفی میکنیم بعد انیمشن رو بهش نسبت میدیم
ImageView animation = (ImageView) findViewById(R.id.imageView1);
animation.setBackgroundResource(R.drawable.animation);
این کد هم برای اینکه انیمشن اجرا شه انتهای صفحت میذاری
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
AnimationDrawable frameAnimation =
(AnimationDrawable) animation.getBackground();
if (hasFocus) {
frameAnimation.start();
}
} else {
frameAnimation.stop();
}
}
}
تموم شد
پاسخ به سوال
mf2010
11 سال پیش
0
0



تمام کار ها را انجام دادم فقط در اینجا ارور داره :
package test.yavari.fa2.test;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.ImageView;
public class ThirdActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third_page);
ImageView animati findViewById(R.id.imageView1);
animation.setBackgroundResource(R.drawable.animation);
@Override
public void onWindowFocusChanged(boolean hasFocus) {
لینک TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus); AnimationDrawable frameAnimati animation.getBackground();
if (hasFocus) {
frameAnimation.start();
}
} else {
frameAnimation.stop();
}
}
}
}
} (11 سال پیش)
پاسخ به سوال
علی
11 سال پیش
0
0
package test.yavari.fa2.test;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.ImageView;
public class ThirdActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third_page);
ImageView animation = (ImageView) findViewById(R.id.imageView1);
animation.setBackgroundResource(R.drawable.animation);
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
AnimationDrawable frameAnimation =
(AnimationDrawable) animation.getBackground();
if (hasFocus) {
frameAnimation.start();
}
} else {
frameAnimation.stop();
}
}
}
}
}
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .



