我有一个带有next和Back按钮的布局和一个ImageSwitcher
当我启动我的应用程序时,布局中没有图像(空白)
当我点击下一个按钮时,第一个图像出现
我想修复代码所以当我启动应用程序时,我看到mt第一个图像没有点击就出现了当我点击我移动到下一张照片
MainActivty Code
Integer[] sabah = {R.drawable.sab_1,R.drawable.sab_2,R.drawable.sab_3,R.drawable.sab_4,R.drawable.sab_5};
int i = 0;
ImageView back_btu,next_btu;
ImageSwitcher imageSwitcher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sabah);
imageSwitcher = (ImageSwitcher)findViewById(R.id.imgSw);
imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView sabimageView = new ImageView(getApplicationContext());
sabimageView.setScaleType(ImageView.ScaleType.FIT_START);
sabimageView.setLayoutParams(new ImageSwitcher.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
return sabimageView;
}
});
Animation in = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.in);
Animation out = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.out);
imageSwitcher.setAnimation(in);
imageSwitcher.setAnimation(out);
back_btu = (ImageView)findViewById(R.id.back_btu);
next_btu =(ImageView)findViewById(R.id.next_btu);
}
public void backBtu(View view) {
if(i >0){
i--;
imageSwitcher.setImageResource(sabah[i]);
}
}
public void nextBtu(View view) {
if(i<sabah.length-1){
i++;
imageSwitcher.setImageResource(sabah[i]);
}
}
}