zoukankan      html  css  js  c++  java
  • Android自定义上拉控件SpringView

    Demo

    先看一下SpringView的效果图:
    SpringView效果图

    1.拖动灰色部分可拖动下方视图,点击jump按钮可让下方视图自行滑动。

    使用方法

    布局文件:

        <com.zql.android.springview.SpringView
            android:id="@+id/spring"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="#ff5533ff">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:text="First View"/>
            </LinearLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:background="#ffeeeeee">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="I am move holder"
                    android:gravity="center"
                    android:layout_centerInParent="true"
                    android:layout_gravity="left"/>
                <Button
                    android:id="@+id/jump"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_alignParentRight="true"
                    android:text="jump"/>
            </RelativeLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="#ff553300">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:text="Second View"/>
            </LinearLayout>
        </com.zql.android.springview.SpringView>
    

    SpringView内部可以容纳两个或三个子view,当只有两个的时候,SringView会自动生成一个供拖拽的视图,当有三个的时候,会把第二个子view作为拖拽视图使用。建议使用三个子view,这样可以自定义拖拽的视图。

    注意点:当使用三个子view的时候,第二个作为拖拽视图的布局要明确layout_height,不能使用match_parent或wrap_content。

    SpringView的事件响应

        public interface OnSpringListener{
            //达到顶部时回调
            void touchTop();
            //达到底部时回调
            void touchBottom();
        }
    

    SpringView自动滑动:

    public void SpringView.jumpUp();
    public void SpringView.jumpDown()
    

    github

    https://github.com/ZhangQinglian/Android-SpringView

  • 相关阅读:
    [luoguP2622] 关灯问题II(状压最短路)
    [luoguP2016] 战略游戏(DP)
    FileUpload
    Mysql -- JDBC
    Mysql优化
    Mysql锁
    Mysql索引
    Mysql事务
    Mysql基本语句
    Listener
  • 原文地址:https://www.cnblogs.com/zqlxtt/p/5072751.html
Copyright © 2011-2022 走看看