Zoomする ImageButton

タッチして画像をズーム表示する ImageButton のサンプルが Android Developer サイトで
紹介されている。

http://developer.android.com/training/animation/zoom.html

ここからダウンロードできる。

ここにあるのは、ズームしてからタッチして戻ると選択状態のハイライトの背景がかかったままになる。

f:id:posturan:20160313193522p:plain



戻った時、、、

f:id:posturan:20160313193515p:plain



これをズームから戻っても元の表示のままにしたいのだが、

f:id:posturan:20160313193456p:plain


戻っても、このようにしたい。

com.example.android.animationsdemo.TouchHighlightImageButton
の init() の中、

TypedArray a = getContext().obtainStyledAttributes(new int[]{ android.R.attr.selectableItemBackground });
mForegroundDrawable = a.getDrawable(0);
mForegroundDrawable.setCallback(this);
a.recycle();

ここら辺を修正すればできると思ったが、attr がよくわからず、
結局、drawableStateChanged メソッドでの invalidate をしないことにした。

    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();

        // Update the state of the highlight drawable to match
        // the state of the button.

//        if (mForegroundDrawable.isStateful()) {
//            mForegroundDrawable.setState(getDrawableState());
//        }
//
//
        // Trigger a redraw.

//        invalidate();
    }

無理やりな方法なので良くないとは思ったけど。