StretchPanel可以根据需要收缩或者展开视图的控件,使用简单方便!

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值