我有2个图像按钮。 imagebutton1上有一张图片作为背景,imagebutton2的背景为空白。如果我点击图像按钮1,图像按钮2将获得图像按钮1的背景图片,如果我再次单击图像按钮2,背景将再次为空白。就像游戏“4pic 1个单词”的概念一样,如果你们熟悉那个。感谢。
答案 0 :(得分:1)
public Bitmap getBitmapFromImageView(ImageView imageView){
Drawable drawable = imageView.getDrawable();
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
bitmap = bitmapDrawable.getBitmap();
}
return bitmap;
}
答案 1 :(得分:1)
你可以这样做..
int minute = 0;
final Drawable d = img2.getDrawable();
img1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (minute == 0) {
img2.setImageDrawable(img1.getDrawable());
minute = 1;
} else {
img2.setImageDrawable(d);
minute = 0;
}
}
});
img2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
img2.setImageDrawable(d);
}
});
根据您的要求更改点击事件。希望它可以帮助您..
答案 2 :(得分:0)
您可以在点击按钮
时使用此功能 public void firstbutton(){
ImageView ImageButton2 = (ImageButton)findViewById(R.id.imageButton2);
ImageButton2 .setImageResource(R.drawable.image1);
}
public void Secondbutton()
ImageView ImageButton1 = (ImageButton)findViewById(R.id.imageButton1);
ImageButton2 .setImageResource(R.drawable.image2);
}
call this method on button click where you want cheers........