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重用時狀態會出現問題!!!
有問題或者建議可以發送郵件到[email protected]

發佈了2 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章