• AndroidSlidingUpPanel 使用控制和简单的分析方法


    滑 - 向上的时间可以飞起来控件的显示区域。分类似至play music有效。


    该控件在主界面中有一个例如以下图红色箭头所指的底部触发区域


    该区域点击的时候被隐藏在下方的内容将网上漂移到顶部,直到被隐藏的内容全然挡住原来的布局。可是这个触发区域仍然存在,如图。

    当被隐藏区域全然显示。这时再次点击触发区域(或者是通过下滑的手势)将恢复到最初的状态。

    一般再未点击的时候。这个触发区域显示一些被隐藏内容的简要信息。

    这就是AndroidSlidingUpPanel的效果了。

    AndroidSlidingUpPanel的实现是使用ViewdragHelper实现的。事实上ViewdragHelper在surport v4中已经能够直接使用了。可是作者直接将ViewdragHelper的全部源代码放到了自己的项目中。

    以下是AndroidSlidingUpPanel库的代码结构:

    当中SlidingUpPanelLayout是一个继承自ViewGroup的类。

    用法:

    .将com.sothree.slidinguppanel.SlidingUpPanelLayout作为根节点放到你activity的layout文件里。

    .layout必须设置gravity属性为top 或者bottom

    .确保SlidingUpPanelLayout有两个子view,一个是主界面。另外一个是向上滑动的界面。

    .SlidingUpPanelLayout的width须要设置成match_parent,height能够是match_parent或者是固定值。

    .默认情况下。整个界面都能够对应滑动和点击事件。你能够通过调用setDragView来约束可滑动的View范围。

    很多其它的使用请參考demo。

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:panelHeight="68dp"
        sothree:shadowHeight="4dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Main Content"
            android:textSize="16sp" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|top"
            android:text="The Awesome Sliding Up Panel"
            android:textSize="16sp" />
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>
    项目给出的demo中当向上滑动的时候actionbar也是跟着慢慢隐藏的。这样的效果必须使用ActionBarOverlay模式:
    <style name="AppTheme">
        <item name="android:windowActionBarOverlay">true</item>
    </style>

    同一时候这样的情况你须要为主区域的布局设置margintop为actionbar的高度:
    ?

    android:attr/actionBarSize

    还须要在代码中动态的改变actionbar:
    public void setActionBarTranslation(float y) {
        // Figure out the actionbar height
        int actionBarHeight = getActionBarHeight();
        // A hack to add the translation to the action bar
        ViewGroup content = ((ViewGroup) findViewById(android.R.id.content).getParent());
        int children = content.getChildCount();
        for (int i = 0; i < children; i++) {
            View child = content.getChildAt(i);
            if (child.getId() != android.R.id.content) {
                if (y <= -actionBarHeight) {
                    child.setVisibility(View.GONE);
                } else {
                    child.setVisibility(View.VISIBLE);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        child.setTranslationY(y);
                    } else {
                        AnimatorProxy.wrap(child).setTranslationY(y);
                    }
                }
            }
        }
    }

    最后要说的是,AndroidSlidingUpPanel在某些方面有点类似与垂直的ViewPager。可是不同点也非常多。假设你想用ViewPager来实现AndroidSlidingUpPanel的效果是非常不明智的。

    项目地址:

    https://github.com/umano/AndroidSlidingUpPanel


    版权声明:本文博主原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    每日一题(文化课)一题---------19/7/30
    XXXXX,这个域名
    CF1037E. Trips
    bzoj3124: [Sdoi2013]直径 树形dp two points
    luogu P3952 时间复杂度 模拟
    AGC016D
    CF444E. DZY Loves Planting
    模拟赛
    HDU 3949 XOR [线性基|高斯消元]
    博客搬家
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4759632.html
Copyright © 2020-2023  润新知