AndroidSlidingUpPanel控件的用法以及简单解析
2014-10-17 12:59
537 查看
一个能够向上滑动的时候往上飞出一个显示区域的控件,类似于play music中的效果。该控件在主界面中有一个如下图红色箭头所指的底部触发区域:该区域点击的时候被隐藏在下方的内容将网上漂移到顶部,直到被隐藏的内容完全挡住原来的布局,但是这个触发区域仍然存在,如图。当被隐藏区域完全显示,这时再次点击触发区域(或者是通过下滑的手势)将恢复到最初的状态。一般再未点击的时候,这个触发区域显示一些被隐藏内容的简要信息。这就是AndroidSlidingUpPanel的效果了。AndroidSlidingUpPanel的实现是使用ViewdragHelper实现的,其实ViewdragHelper在surport v4中已经可以直接使用了,但是作者直接将ViewdragHelper的所有源码放到了自己的项目中。下面是AndroidSlidingUpPanel库的代码结构:其中SlidingUpPanelLayout是一个继承自ViewGroup的类。使用方法:.将
或者bottom
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
相关文章推荐
- android开发步步为营之100:开源项目SlidingUpPanelLayout简单用法
- AndroidSlidingUpPanel 使用控制和简单的分析方法
- [Android UI控件] AndroidSlidingUpPanel 分析
- Android注解解析,注解用法,仿xUtils用注解初始化控件、点击事件(二)
- Android ListView控件基本用法以及范例
- 打造Android集合控件数据绑定(支持添加监听,支持AbsListView与RecycleView,支持异步加载等)(二)ORM注解以及解析
- Android 自定义九宫格控件Gridview用法以及属性
- Android笔记---常用控件以及用法
- Android的控件CheckBox、ImageView以及ListView的自定义Adapter用法
- android SlidingUpPanel (一)
- Android中DatePicker控件用法解析
- AndroidSlidingUpPanel简析
- Day3.4--Android简单UI控件之ImageView以及ScaleType的使用
- Android IOC 之 注解绑定控件 以及事件 事例 代码简单注释讲解
- Android注解解析,注解用法,仿xUtils用注解初始化控件、点击事件(一)
- Android自底部平滑向上滑出面板的AndroidSlidingUpPanel
- 【Android成长之路】最常用和最难用的控件——ListView的浅谈(ListView 的简单用法)
- android中Date对象的简单应用,以及TimePicker和DatePicker控件
- Android注解解析,注解用法,仿xUtils用注解初始化控件、点击事件(一)
- Android 解析Json 和Json数组 以及Gson的简单应用