0

我有 2 个图像按钮。imagebutton1 上有一张图片作为背景,而 imagebutton2 有一个空白背景。如果我单击 imagebutton1,imagebutton2 将获得 imagebutton1 的背景图片,我该如何做到这一点,如果我再次单击 imagebutton2,背景将再次为空白。就像你们熟悉的游戏“4pic 1 word”的概念一样。谢谢。

4

3 回答 3

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);
        }
    });

根据您的要求更改点击事件。希望它对您有所帮助..

于 2013-04-16T05:54:57.497 回答
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;
}
于 2013-04-16T05:39:42.927 回答
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........
于 2013-04-16T05:42:47.447 回答