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


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

转载于:https://www.cnblogs.com/yxwkf/p/4759632.html

AndroidSlidingUpPanel 是一个上拉面板, 就是向上滑动的时候往上飞出一个显示面板控件, 该库效果在 Google Music, Google Maps and Rdio等 App 中用到。 效果图: 用法:使用com.sothree.slidinguppanel.SlidingUpPanelLayout作为您的活动布局的根元素。 布局必须设置为顶部或底部。请确保它有两个元素。 第一个元素是你的主要布局。第二个元素是你的向上滑动面板布局。 主要布局应当具有的宽度和高度设置为match_parent。 滑动的布局的宽度应设置为match_parent;高度设置为match_parent,WRAP_CONTENT或最大desireable高度。 如果您想定义高度屏幕为percetange,可将其设置为match_parent,滑动视图定义为layout_weight属性。  默认情况下,整个面板将作为拖动区域和将截获的点击和拖动事件。可以通过使用setDragView方法或umanoDragView属性限制牵引区到特定的图。 想了解更多信息,请参考示例代码:<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:umanoPanelHeight="68dp"     sothree:umanoShadowHeight="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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值