四畳半の秘密基地

さあ、今日はどんな実験をしよう

MENU

AndroidでFacebook LikeなImageView

FacebookAndroidアプリってタイムラインとかに表示されている画像を拡大するとき、
切り抜かれてる画像が画面幅に広がりながら全体が表示されてかっこいい。(表現難しい)

GridViewとかで表示している画像一覧をタップするとFacebookのように画像拡大できないかな
と思っていろいろやってみました。
・scaleType, adjustViewBoundsをごにょごにょして拡大
・FrameLayoutの上にImageViewを乗せてFrameLayoutを拡大

切り抜かれてる時点でscaleTypeはcenterCropだよなとか思いながら、試してみましたができず・・・

ネットに良いサンプル転がってないかぁと検索しているとStackOverFlowで発見

How to animate ImageView from center-crop to fill the screen and vice versa (facebook style)?

回答にソースコードが載っていて早速コピペして実行したら動きました!
中身を見ていると、ObjectAnimatorで拡大+位置補正処理をしている所は同じだったんですが、プロパティ名が見たことないものが入ってました。

public void runEnterAnimation(final int containerWidth, final int containerHeight) {
        final ObjectAnimator widthAnim = ObjectAnimator.ofInt(mFullImageView, "contentWidth", mFitSizeBitmap.x)
                .setDuration(ANIM_DURATION);
        final ObjectAnimator heightAnim = ObjectAnimator.ofInt(mFullImageView, "contentHeight", mFitSizeBitmap.y)
                .setDuration(ANIM_DURATION);
        final ObjectAnimator xAnim = ObjectAnimator.ofInt(mFullImageView, "contentX",
                (containerWidth - mFitSizeBitmap.x) / 2).setDuration(1000);
        final ObjectAnimator yAnim = ObjectAnimator.ofInt(mFullImageView, "contentY",
                (containerHeight - mFitSizeBitmap.y) / 2).setDuration(1000);
        widthAnim.start();
        heightAnim.start();
        xAnim.start();
        yAnim.start();
    }

公式サイトを探してみましたが見つかりませんでした。皆こういう情報をどこから仕入れてくるのかとても知りたい・・・