0

グロー効果は正常に機能しています。私の疑問は、グロー効果を隠す方法ですか?imageviewをクリックした場合、そのときだけグロー効果を表示したいのですが、クリック中にグロー効果を非表示にして表示する方法を教えてください。

コード:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // An added margin to the initial image
        int margin = 24;
        int halfMargin = margin / 2;

        // the glow radius
        int glowRadius = 16;

        // the glow color
        int glowColor = Color.rgb(0, 192, 255);

        // The original image to use
        Bitmap src = BitmapFactory.decodeResource(getResources(),
                R.drawable.test);

        // extract the alpha from the source image
        Bitmap alpha = src.extractAlpha();

        // The output bitmap (with the icon + glow)
        Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
                src.getHeight() + margin, Bitmap.Config.ARGB_8888);

        // The canvas to paint on the image
        Canvas canvas = new Canvas(bmp);

        Paint paint = new Paint();
        paint.setColor(glowColor);

        // outer glow
        paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
        canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

        // original icon
        canvas.drawBitmap(src, halfMargin, halfMargin, null);
        setContentView(R.layout.activity_main);

        ((ImageView) findViewById(R.id.bmpImg)).setImageBitmap(bmp);

    }
}

現在のスクリーンショット:

ここに画像の説明を入力してください

4

3 に答える 3

2

onclicklistener を設定し、次のコードを実装します。

.setOnClickListener(clicklistener);


private OnClickListener backListener = new OnClickListener() {
        public void onClick(View v) {
    // An added margin to the initial image
        int margin = 24;
        int halfMargin = margin / 2;

        // the glow radius
        int glowRadius = 16;

        // the glow color
        int glowColor = Color.rgb(0, 192, 255);

        // The original image to use
        Bitmap src = BitmapFactory.decodeResource(getResources(),
                R.drawable.test);

        // extract the alpha from the source image
        Bitmap alpha = src.extractAlpha();

        // The output bitmap (with the icon + glow)
        Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
                src.getHeight() + margin, Bitmap.Config.ARGB_8888);

        // The canvas to paint on the image
        Canvas canvas = new Canvas(bmp);

        Paint paint = new Paint();
        paint.setColor(glowColor);

        // outer glow
        paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
        canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

        // original icon
        canvas.drawBitmap(src, halfMargin, halfMargin, null);
}}
于 2012-10-11T07:51:44.433 に答える
2

setMaskFilter()このようにnullを設定できます

paint.setMaskFilter(null);

そして、あなたはただ設定する必要がありますpaint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));

このためには、アプリケーションスコープのペイントオブジェクトを保持する必要があるため、このペイントオブジェクトは別のクラスまたはアクティビティで必要な場所にアクセスできます。または、フラグをtrueに設定してグロー効果を表示し、フラグを何も設定しません(デフォルト)

于 2012-10-05T11:21:57.670 に答える
0

これを行う簡単な方法は、を使用することStateListDrawableです。

2つの画像を作成します。1つは通常の状態用で、もう1つは押された状態(グローあり)用です。これをres/drawable/button_drawable.xmlで使用します。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/image_normal"
        android:state_enabled="true"/>
    <item
        android:drawable="@drawable/image_pressed"
        android:state_pressed="true"/>
</selector>

そして、それをボタンドローアブルとして使用します。

((ImageView) findViewById(R.id.bmpImg)).setImageDrawable(getResources().getDrawable(R.drawable.button_drawable));
于 2012-10-05T11:15:28.967 に答える