Android 检查动画滑动面板是否处于活动状态

Android 检查动画滑动面板是否处于活动状态,android,animation,Android,Animation,我成功地在我的应用程序中实现了一个向下滑动面板。用我在stackoverflow上找到的答案中的动画 但我正在尝试实现一些特性。我不知道该怎么做。我已经坐了好几个小时,试图找出如何做,但我仍然无法解决我的问题 我有一个包含2个按钮和一个空框架布局的布局。单击按钮后,片段事务将片段加载到空的framelayout中,布局向下滑动。这些部件都很好用 我现在遇到的问题是: 1.如何检查滑动面板是否已激活。 2.如果面板已处于活动状态,如何在单击同一按钮时阻止面板向上滑动。 3.同样,将片段事务放在按钮

我成功地在我的应用程序中实现了一个向下滑动面板。用我在stackoverflow上找到的答案中的动画

但我正在尝试实现一些特性。我不知道该怎么做。我已经坐了好几个小时,试图找出如何做,但我仍然无法解决我的问题

我有一个包含2个按钮和一个空框架布局的布局。单击按钮后,片段事务将片段加载到空的framelayout中,布局向下滑动。这些部件都很好用

我现在遇到的问题是: 1.如何检查滑动面板是否已激活。 2.如果面板已处于活动状态,如何在单击同一按钮时阻止面板向上滑动。 3.同样,将片段事务放在按钮的onClick方法中,即使片段处于活动状态,也会重新加载该片段。我该如何阻止这一切

请注意,我对应用程序开发还比较陌生。我曾试图解决这个问题,但到目前为止还没有成功。所以任何帮助都是有用的

另外,我想知道是否有更好的方法来实现这个滑动面板? 多谢各位

这是我的密码:

  • ExpandCollapseAnimation类,用于保存动画

    public class ExpandCollapseAnimation extends Animation {
    private FrameLayout mAnimatedView;
    private int mEndHeight;
    private int mType;
    
    /**
     * Initializes expand collapse animation, has two types, collapse (1) and expand (0).
     * @param view The view to animate
     * @param duration
     * @param type The type of animation: 0 will expand from gone and 0 size to visible and layout size defined in xml. 
     * 1 will collapse view and set to gone
     */
    public ExpandCollapseAnimation(FrameLayout view, int duration, int type) {
        setDuration(duration);
        mAnimatedView = view;
        mEndHeight = mAnimatedView.getLayoutParams().height;
        mType = type;
        if(mType == 0) {
            mAnimatedView.getLayoutParams().height = 0;
            mAnimatedView.setVisibility(View.VISIBLE);
        }
    }
    
    
    
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);
        if (interpolatedTime < 1.0f) {
            if(mType == 0) {
                mAnimatedView.getLayoutParams().height = (int) (mEndHeight * interpolatedTime);
            } else {
                mAnimatedView.getLayoutParams().height = mEndHeight - (int) (mEndHeight * interpolatedTime);
            }
                mAnimatedView.requestLayout();
        } else {
            if(mType == 0) {
                mAnimatedView.getLayoutParams().height = mEndHeight;
                mAnimatedView.requestLayout();
            } else {
                mAnimatedView.getLayoutParams().height = 0;
                mAnimatedView.setVisibility(View.GONE);
                mAnimatedView.requestLayout();
                mAnimatedView.getLayoutParams().height = mEndHeight;
            }
        }
      }
    }
    

    先解决你的问题怎么样?适当的代码块等将真正有助于吸引更多我编辑过的代码。谢谢
       public class MainActivity extends ActionBarActivity {
    
        private boolean mActive = false;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
    
            btntap();
            btnTwoTap();
    
    
        }
    
    
    
    
        public void btnTwoTap() {
            Button button2 = (Button) findViewById(R.id.openAnimTwo);
            FrameLayout frameLayout= (FrameLayout) findViewById(R.id.slidin);
    
            button2.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
    
                FragmentManager fm = getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                Fragment fragmen = new TestFragTwo();
                ft.replace(R.id.slidin, fragmen);
                ft.commit();
    
                }
            });
    
        }
    
    
    
    
        private void btntap() {
    
    
            final FrameLayout animatedFrameLayout = (FrameLayout) findViewById(R.id.slidin);
    
            final Button button = (Button) findViewById(R.id.openAnim);
    
            button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
    
    
    
                    ExpandCollapseAnimation animation = null;
    
                    if(mActive) {
                        animation = new ExpandCollapseAnimation(animatedFrameLayout, 1500, 1);
                        mActive = false;
    
                    } 
                    else if (mActive = false){
    
                        animation = new ExpandCollapseAnimation(animatedFrameLayout, 0, 1);
                    }
                    else {
                        animation = new ExpandCollapseAnimation(animatedFrameLayout, 1000, 0);
                        mActive = true;
                    }
                    animatedFrameLayout.startAnimation(animation);
    
                    //button.setVisibility(View.GONE);
    
    
                    }
            });
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }