我的listactivity
应用程序形成了很多行,一行是图像幻灯片,当您单击该行打开活动显示ImageView
时,还有一个项目的选项菜单(幻灯片动画设置),当您单击它时,它会打开复选框首选项动画屏幕,其中包含多个复选框每个都将不同的动画应用于图像幻灯片,用户可以通过选中其复选框动画名称或取消选中所有复选框来确定幻灯片具有许多可用动画的图像,因此幻灯片活动必须以 viewpager 模式显示图像。
android:defaultValue="true"
第一个动画是淡入淡出动画。但是:当您打开幻灯片活动时,它会以 imagepager 模式打开图像,并忽略 android:defaultValue="true"
淡入淡出复选框,
然后转到首选项屏幕选择另一个动画然后返回幻灯片活动,它不应用新动画,我必须多次按下返回按钮直到完成在寻呼机中滚动的所有图像然后它应用下一个动画,有时它卡在图像寻呼机上并冻结,正常行为是应用下一个动画,一旦按下返回按钮返回幻灯片。
另一件事是,当我处于图像viewpager
模式并滚动它时,它会滚动几张图像,然后回到第一个图像,然后我再次滚动图像,然后突然回到第一个图像,依此类推。
整个项目可以从 这里下载
任何帮助将不胜感激。
幻灯片放映.java
public class SlideShow extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
private int[] IMAGE_IDS = {
R.drawable.day_one_1, R.drawable.day_one_2, R.drawable.day_one_3,
R.drawable.day_one_4, R.drawable.day_one_5, R.drawable.day_one_6,
R.drawable.day_one_7, R.drawable.day_one_8, R.drawable.day_one_9,
R.drawable.day_one_10, R.drawable.day_one_11, R.drawable.day_one_12,
R.drawable.day_one_13, R.drawable.day_one_14, R.drawable.day_one_15,
R.drawable.day_one_16,R.drawable.day_one_17,R.drawable.day_one_18,
R.drawable.day_one_19,R.drawable.day_one_20
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide);
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000; // delay for 1 sec.
int period = 8000; // repeat every 4 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
private void AnimateandSlideShow() {
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
boolean animation = getPrefs.getBoolean("animation", true);
boolean animation_one = getPrefs.getBoolean("animation_one", false);
boolean animation_two = getPrefs.getBoolean("animation_two", false);
boolean animation_three = getPrefs.getBoolean("animation_three", false);
boolean animation_four = getPrefs.getBoolean("animation_four", false);
boolean animation_five = getPrefs.getBoolean("animation_five", false);
if (animation == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
slidingimage.startAnimation(rotateimage);
}else if(animation_one == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in);
slidingimage.startAnimation(rotateimage);
}else if (animation_two == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_out);
slidingimage.startAnimation(rotateimage);
}else if (animation_three == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.bounce);
slidingimage.startAnimation(rotateimage);
}else if(animation_four == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in_2);
slidingimage.startAnimation(rotateimage);
}else if (animation_five == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.flip);
slidingimage.startAnimation(rotateimage);
}else if(animation == false && animation_one == false && animation_two == false){
Intent intent = new Intent(SlideShow.this, ImagePager.class);
startActivity(intent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_settings:
Intent p = new Intent("com.test.test.SETTING");
startActivity(p);
break;
}
return false;
}
}
ImagePager.java
public class ImagePager extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pager);
ImagePagerAdapter adapter = new ImagePagerAdapter(this, imageArra);
ViewPager myPager = (ViewPager) findViewById(R.id.myimagepager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
}
private int imageArra[] = { R.drawable.day_one_1, R.drawable.day_one_2, R.drawable.day_one_3,
R.drawable.day_one_4, R.drawable.day_one_5, R.drawable.day_one_6,
R.drawable.day_one_7, R.drawable.day_one_8, R.drawable.day_one_9,
R.drawable.day_one_10, R.drawable.day_one_11, R.drawable.day_one_12,
R.drawable.day_one_13, R.drawable.day_one_14, R.drawable.day_one_15,
R.drawable.day_one_16,R.drawable.day_one_17,R.drawable.day_one_18,
R.drawable.day_one_19,R.drawable.day_one_20
};
public class ImagePagerAdapter extends PagerAdapter {
Activity activity;
int[] imageArray;
public ImagePagerAdapter(Activity act, int[] imgArra) {
imageArray = imgArra;
activity = act;
}
public int getCount() {
return imageArray.length;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater)collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_pager, null);
ImageView im=(ImageView) layout.findViewById(R.id.pager_imageView);
im.setImageResource(imageArray[position]);
((ViewPager) collection).addView(layout, 0);
return layout;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_settings:
Intent p = new Intent("com.test.test.SETTING");
startActivity(p);
break;
}
return false;
}
}