68

この LinearLayout 内に LinearLayout と ImageView があります。

ImageView の翻訳効果があります。

// v = ImageView    
ObjectAnimator animation2 = ObjectAnimator.ofFloat(v, "translationY", 200);
                        animation2.setDuration(3000);
                        animation2.setTarget(v);
                        animation2.start();

アニメーションは機能しますが、ImageView が LinearLayout の外に出ると消えます。

LinearLayout の高さを変更せずに修正するにはどうすればよいですか。

4

6 に答える 6

89

ImageView が属する ViewGroup を見つけて、ViewGroup.setClipChildren(false)を適用します。デフォルトでは、子の描画は親 ViewGroup の境界に制限されています。

于 2013-08-05T01:15:19.230 に答える
16

私の実装。それはおそらく誰かを助けることができます:

Java のバージョン:

public static void setAllParentsClip(View v, boolean enabled) {
    while (v.getParent() != null && v.getParent() instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) v.getParent();
        viewGroup.setClipChildren(enabled);
        viewGroup.setClipToPadding(enabled);
        v = viewGroup;
    }
}

を呼び出し setAllParentsClip(yourView, false);て、すべての親でクリッピングを無効にします。

編集:

拡張機能としての Kotlin のバージョン:

fun View.setAllParentsClip(enabled: Boolean) {
    var parent = parent
    while (parent is ViewGroup) {
        parent.clipChildren = enabled
        parent.clipToPadding = enabled
        parent = parent.parent
    }
}

電話:yourView.setAllParentsClip(false)

于 2016-03-24T16:29:59.060 に答える
1

私の場合、clipChildren は何もしませんでしたがclipToPadding="false"、問題を修正しました。図に行きます。

于 2015-06-11T16:21:28.480 に答える
0
try to update camera position as in my case below:
 ValueAnimator lockAnimator = ValueAnimator.ofFloat(1, 0);     // value from 0 to 1
                lockAnimator.setDuration(500);
                lockAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator pAnimation) {
                        float value = (Float) (pAnimation.getAnimatedValue());
                        if (value < .6 && flipped) {
                            if (preview != null)
                                mCanvasImage.setImageBitmap(preview);
                            else
                                mCanvasImage.setImageBitmap(imageBitmap);
                            flipped = false;
                        }
                        if (value > .3 && value < .7) {
                            lyt_rlt_container.setCameraDistance(lyt_rlt_container.getCameraDistance() - 100);
                        } else {
                            lyt_rlt_container.setCameraDistance(lyt_rlt_container.getCameraDistance() + 100);
                        }
                        lyt_rlt_container.setRotationY(180 * value);

                    }
                });
                lockAnimator.start();
于 2017-01-03T10:50:41.867 に答える