1

こんにちは、viewGroup をアニメーション化するために、ここにあるSeth のメソッドを借りています。それはうまく機能しますが、間違った方向に進みます - Animation クラスを使用/拡張するのはこれが初めてで、ビューのサイズを縮小する方法がわかりません - これにより拡張されます。

以下はクラスと私がそれを使用する方法です。どんな助けでも大歓迎です。

public class ContainerAnim extends Animation {
    int targetWidth;
    View view;
    boolean opened;

    public ContainerAnim(View v, int targetWidth, boolean opened) {
        this.view = v;
        this.targetWidth = targetWidth;
        this.opened = opened;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        int newWidth;
        if (opened) {
            newWidth = (int) (targetWidth * interpolatedTime);
        } else {
            newWidth = (int) (targetWidth * (1 - interpolatedTime));
        }
        view.getLayoutParams().width = newWidth;
        view.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth,
            int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}

使用法:

... case R.id.menu_shrink:
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            FrameLayout frame = (FrameLayout) findViewById(R.id.listFragment_container);

            ContainerAnim set = new ContainerAnim(frame, 100, true);
            set.setDuration(200);
            LayoutAnimationController c = new LayoutAnimationController(set,
                    0.25f);
            frame.setLayoutAnimation(c);
            frame.startLayoutAnimation();

            ft.commit();
...
4

1 に答える 1

0

その 3 番目のパラメーター (ブール値) の使用法を混同したと思います。それを「opened」と呼び、true を渡します。これは、縮小したいからです。ただし、これは元のコードでの使用法とは逆です。私のコードでは、ビューが閉じられた場合、ブール値は true でしたが、拡大したかったのです。

"および d = 方向を指定するブール値 (true = 展開、false = 折りたたみ)。"

アニメーション クラスの条件を if(!opened){} に変更すると、機能するはずです。または、true の代わりに false を渡します。または、true を渡しますが、変数を「opened」ではなく「closed」に変更します。

-セス

于 2012-02-15T00:56:31.857 に答える