更改图像按钮上的图像单击android

时间:2012-04-16 11:47:27

标签: android

我正在显示用于页面布局控制的动态图像以显示页面数量,现在我将默认焦点放在第一个图像按钮上,现在当我点击下一个图像按钮然后我想要替换第一个图像按钮使用简单的图像按钮和带有可聚焦图像按钮的单击按钮,我也使用了invalidate()方法,但尚未解决,请帮忙。

if(i==0){
    Drawable dr = getResources().getDrawable(R.drawable.bullet_2);
    Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
    Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 10, 10, true));
    b1.setImageDrawable(d);
    flag = false;
}
else {
    Drawable dr = getResources().getDrawable(R.drawable.bullet_1);
    Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
    // Scale it to 50 x 50
    Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 10, 10, true));
    // Set your new, scaled drawable "d"
    b1.setImageDrawable(d);
}
b1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        //Object id = b1.getTag();
        Object tag = b1.getTag();
        System.out.println("value of id:::" +tag.toString());
        Global.tagvalue = tag.toString();

        flag = true;

        if(flag == true){
            Drawable dr = getResources().getDrawable(R.drawable.bullet_2);
            Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
            // Scale it to 50 x 50
            Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 10, 10, true));
            // Set your new, scaled drawable "d"
            b1.setImageDrawable(d);
            b1.invalidate();
            WindowManager w = getWindowManager(); 
            Display dis = w.getDefaultDisplay(); 
            int width = dis.getWidth(); 
            int height = dis.getHeight(); 
            System.out.println("value of width of screen::" +width);

            horlist.mNextX = width*Integer.parseInt(tag.toString());
        }
        else {
            Drawable dr = getResources().getDrawable(R.drawable.bullet_1);
            Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
            // Scale it to 50 x 50
            Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 10, 10, true));
            // Set your new, scaled drawable "d"
            b1.setImageDrawable(d);
            b1.invalidate();
        }

1 个答案:

答案 0 :(得分:0)

你可以设置图像为空

imgBtn.setImageBitmap(空);

b1.setImageDrawable(0);