Android:如何更改我的ExpandAnimation类以正确处理动画?

Android:如何更改我的ExpandAnimation类以正确处理动画?,android,android-animation,Android,Android Animation,这是我在Udnic上的动画课-谢谢, 但我不是从关闭的位置而是从打开的位置使用它,它是跳跃,动作不正确 我该怎么办 public class ExpandAnimation extends Animation { private View mAnimatedView; private LinearLayout.LayoutParams mViewLayoutParams; public int mMarginStart, mMarginEnd; priva

这是我在Udnic上的动画课-谢谢, 但我不是从关闭的位置而是从打开的位置使用它,它是跳跃,动作不正确

我该怎么办

    public class ExpandAnimation extends Animation {
    private View mAnimatedView;
    private LinearLayout.LayoutParams mViewLayoutParams;
    public int mMarginStart, mMarginEnd;
    private boolean mIsVisibleAfter = false;
    private boolean mWasEndedAlready = false;
    private ImageView mImageView;
    /**
     * Initialize the animation
     * @param view The layout we want to animate
     * @param duration The duration of the animation, in ms
     */
    public ExpandAnimation(View view, int duration, ImageView imageView) {
        setDuration(duration);
        mImageView = imageView;
        mAnimatedView = view;
        mViewLayoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();

        mMarginStart = mMarginEnd = 0;
        // decide to show or hide the view
        mIsVisibleAfter = (view.getVisibility() == View.VISIBLE);
        //mIsVisibleAfter = (mViewLayoutParams.bottomMargin == 0);

        mMarginStart = mViewLayoutParams.bottomMargin;
        if(mMarginStart != 0)
            mMarginStart = 0 - view.getHeight();
        mMarginEnd = (mMarginStart == 0 ? (0 - view.getHeight()) : 0);

        view.setVisibility(View.VISIBLE);
        mImageView.setImageResource(R.drawable.expand_open);
    }

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


    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);

        if (interpolatedTime < 1.0f) {

            // Calculating the new bottom margin, and setting it
            mViewLayoutParams.bottomMargin = mMarginStart
                    + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

            // Invalidating the layout, making us seeing the changes we made
            mAnimatedView.requestLayout();

            // Making sure we didn't run the ending before (it happens!)
        } else if (!mWasEndedAlready) {
            mViewLayoutParams.bottomMargin = mMarginEnd;
            mAnimatedView.requestLayout();

//          if (mIsVisibleAfter) {
            if(mMarginEnd != 0) {
                mAnimatedView.setVisibility(View.GONE);
                mImageView.setImageResource(R.drawable.expand_close);
            }
            mWasEndedAlready = true;
        }
    }
}

我也面临同样的问题。你在这个问题上运气好吗?哦,是的,我改变了我的XML,放上你的XML,我会努力解决它。谢谢你的快速回复。不管怎样,我修复了这个问题,这个问题在我看来是可见性处理代码。不过谢谢你的帮助没问题,如果你还需要什么,我会尽力帮助你。