Android 展开、收起

来源:互联网 发布:阿松手办淘宝 编辑:程序博客网 时间:2024/06/07 01:15

可以加动画可以在listview中使用,使用中有问题联系:1808418098(微信、QQ)
ViewStub的使用

首先看效果:

点击按钮前:




点击后:




主布局:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical">       <ViewStub        android:id="@+id/stub"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout="@layout/text_layout" />    <Button        android:id="@+id/btn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Traggle" /></LinearLayout>

ViewStub最后一行

text_layout.xml

<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/gsl"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:text="内容内容" ></TextView>

源码:

    private boolean mShowed;    private View mTextPanel;
  btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                // TODO Auto-generated method stub                if (mTextPanel == null) {                    mTextPanel = ((ViewStub) findViewById(R.id.stub)).inflate();                                 }                if (mShowed == false) {                    mShowed = true;                    showPanel(mTextPanel, true);                                  } else {                    mShowed = false;                    hidePanel(mTextPanel, true);                   
 private void showPanel(View panel, boolean slideUp) {//        panel.startAnimation(AnimationUtils.loadAnimation(this,//                slideUp ? R.anim.slide_in : R.anim.slide_out_top));        panel.setVisibility(View.VISIBLE);    }    private void hidePanel(View panel, boolean slideDown) {//        panel.startAnimation(AnimationUtils.loadAnimation(this,//                slideDown ? R.anim.slide_out : R.anim.slide_in_top));        panel.setVisibility(View.GONE);    }

} } });
                                             
0 0
原创粉丝点击