StretchPanel
最近在工作中要用到的效果,干脆写了一个自定义的控件。
控件很简单,是个上下部分的视图,下半部分可以根据需求收缩或者展开,过程中有动画,提升用户的使用体验。
How to use
-1.首先是xml的配置
<com.example.widget.StretchPanel
android:id="@+id/stretchPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="4dp"
android:background="@drawable/itembg">
</com.example.widget.StretchPanel>
或者
<com.example.widget.StretchPanel
xmlns:stretch="http://schemas.android.com/apk/res-auto"
android:id="@+id/stretchPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
stretch:contentView="@layout/view_content"
stretch:stretchView="@layout/view_stretch"
android:padding="2dip" >
</com.example.widget.StretchPanel>
-2.在界面初始化代码中添加:
// xml中没有指定相关视图id的话,需要代码添加
final StretchPanel panel = (StretchPanel) findViewById(R.id.stretchPanel);
final View contentView = View.inflate(this, R.layout.view_content, null);
final View stretchView = View.inflate(this, R.layout.view_stretch, null);
panel.setStretchView(stretchView);
panel.setContentView(contentView);
panel.setStretchAnimationDuration(200);
panel.setHandleClikeEventOnThis(contentView);//点击事件可以调用该方法或者完全自己实现
// xml中指定了id的话
final StretchPanel panel = (StretchPanel) findViewById(R.id.stretchPanel);
panel.setHandleClikeEventOnThis(panel.getContentView())
PS:demo中在listview中使用该控件时,由于没有管理item开关的状态,因此在view重用时状态会出现问题!!!
有问题或者建议可以发送邮件到flytopc@hotmail.com