我正在尝试创建一个图片库,其中包含一种效果,即当您单击图像时,它会转动并显示不同的图像。在这种情况下,当您单击图像1时,它会转动并显示图像11,当您单击图像2时,它将转动并显示图像12,依此类推。 我已经完成了画廊,但我不知道如何实现这种效果。我将不胜感激任何帮助。
public class Carrusel extends Activity implements OnClickListener {
ImageView lastClicked = null;
int padding = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
LinearLayout l;
l = (LinearLayout) findViewById(R.id.carrusel);
int[] images = new int[] { R.drawable.image1, R.drawable.image2,
R.drawable.image3,R.drawable.image4,R.drawable.image5,
R.drawable.image6,R.drawable.image7,R.drawable.image8,
R.drawable.image9,R.drawable.image10,R.drawable.image11,
R.drawable.image12, R.drawable.image13,R.drawable.image14,
R.drawable.image15,R.drawable.image16,R.drawable.image17,
R.drawable.image18,R.drawable.image19,R.drawable.image20 };
for (int i = 0; i <10; i++) {
ImageView iv = new ImageView(this);
iv.setImageResource(images[i]);
iv.setPadding(padding, padding, padding, padding);
iv.setOnClickListener(this);
l.addView(iv);
}
}
@Override
public void onClick(View v) {
if (v instanceof ImageView) {
if (lastClicked != null) {
lastClicked.setPadding(padding, padding, padding, padding);
lastClicked.invalidate();
}
v.setPadding(0, 0, 0, 0);
v.invalidate();
lastClicked = (ImageView) v;
}
}
}