我是 android 的初学者...在我的应用程序中,我需要显示上一个和下一个图像.. 我到了这里,但是图像被打乱了,没有通过单击上一个和下一个按钮获得正确的上一个和下一个图像....这里是我的代码。 ..
public class MainActivity extends Activity implements OnClickListener{
ImageButton ib_left_arrow, ib_right_arrow;
ImageView slidingimage;
Animation rotateimage;
public int currentimageindex = 0;
private int[] IMAGE_IDS = { R.drawable.image1, R.drawable.image2,
R.drawable.image3};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.movies);
ib_left_arrow = (ImageButton) findViewById(R.id.iv_left_arrow);
ib_right_arrow = (ImageButton) findViewById(R.id.iv_right_arrow);
ib_left_arrow.setOnClickListener(this);
ib_right_arrow.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.iv_left_arrow:
slidingimage = (ImageView) findViewById(R.id.ImageView3_Left);
slidingimage.setBackgroundResource(IMAGE_IDS[currentimageindex% IMAGE_IDS.length]);
currentimageindex--;
rotateimage = AnimationUtils.loadAnimation(this,R.anim.slide_in_left);
slidingimage.startAnimation(rotateimage);
break;
case R.id.iv_right_arrow:
slidingimage = (ImageView) findViewById(R.id.ImageView3_Left);
slidingimage.setBackgroundResource(IMAGE_IDS[currentimageindex % IMAGE_IDS.length]);
currentimageindex++;
rotateimage = AnimationUtils.loadAnimation(this,R.anim.slide_in_right);
slidingimage.startAnimation(rotateimage);
break;
}
}
}
任何想法 ???