一个包括拖拽、滚动、动画、背景模糊功能的安卓UI布局

时间:2017-05-12 09:45 来源:互联网 作者:源码搜藏收藏

  • 源码类别:布局类Layouts
  • 源码大小:未知
  • 编码格式:gbk,utf8,不限
  • 运行环境:Android studio
  • 广告推荐

这是一个辅助开发的UI库,适用于某些特殊场景,如固定范围拖拽、动画、背景模糊效果等。直接看下效果图会直观点。

Screenshot

Drag模式,能够拖拽指定的 View,并能和 ViewPager 进行联动,实现拖拽和 ScrollView 的平滑滚动,带有坠落回弹效果:

Animate模式,能够实现指定 View 退出进入的动画效果,并能和 ViewPager 进行联动:

Blur模糊效果,包括局部模糊和全图模糊两种,实现伪动态模糊效果(之所以叫做伪动态模糊是因为该功能实现是通过背景模糊预处理再来动态加载实现的,如果实时进行模糊处理容易造成界面卡顿,所以该功能对静态背景比较实用)。转GIF图有点模糊,大体看下效果。

外部拖拽,在屏幕上垂直滑动就可对视图进行拖拽,能够设置主视图滑动折叠

 

相关内容

实现效果如上面的图片所示,这里简单说明下用到的哪些东西。

 

  • 拖拽滚动功能主要用到了 ViewDragHelper 和 ScrollerCompat 这两个辅助类,ViewDragHelper 内部滚动也是由 ScrollerCompat 实现;
  • 动画效果主要参考了代码家的开源项目AndroidViewAnimations,引用了里面一部分动画,也有自定义动画功能,不过现在用起来可能还不够人性化,可以参考下;
  • 模糊效果用到了RenderScript这个辅助开发工具包,因为原生API需要17才能很好地使用模糊处理,这里使用了RenderScript支持包,所以在项目配置的时候需要进行该功能的支持,详见项目的使用;
  • 对于模糊时的背景获取和模糊处理参考了500px-android-blur这个项目,里面的设计想法值得学习一下;

 

 

使用方法

依赖库的方法看Github上说明。

 

在布局中引用:

 

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <com.dl7.drag.DragSlopLayout  
  2.     android:id="@+id/drag_layout"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@android:color/black"  
  6.     app:fix_height="80dp"  
  7.     app:mode="drag">  
  8.         <!-- Content View -->  
  9.         <android.support.v4.view.ViewPager  
  10.         android:id="@+id/vp_photo"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="match_parent"/>  
  13.   
  14.         <!-- Drag View -->  
  15.         <LinearLayout  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="wrap_content"  
  18.         android:orientation="vertical">  
  19.         // ......  
  20.     </LinearLayout>  
  21.     // ......  
  22. </com.dl7.drag.DragSlopLayout>  

 

如果 Content View 为 ViewPager,通过以下方法来实现联动效果:

[java] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. mDragLayout.interactWithViewPager(true);  

如果 Drag View 包含 ScrollView 或则 NestedScrollView,通过以下方法来实现平滑滚动:

[java] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. mDragLayout.setAttachScrollView(mSvView);  
设置 Content View 的模糊效果:

 

[java] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. mDragLayout.setEnableBlur(true);    // 开启模糊  
  2. mDragLayout.setBlurFull(true);  // 设置全背景模糊,默认为局部模糊  
  3. mDragLayout.updateBlurView();   // 更新模糊背景  
控制 Drag View 的进入和退出:

 

 

[java] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. mDragLayout.scrollInScreen(int duration);   // Drag 模式  
  2. mDragLayout.scrollOutScreen(int duration);  // Drag 模式  
  3.   
  4. mDragLayout.startInAnim();  // Animate 模式  
  5. mDragLayout.startOutAnim(); // Animate 模式  
  6. mDsLayout.setAnimatorMode(DragSlopLayout.FLIP_Y);   // 设置动画模式  

 

设置拖拽监听

 

[java] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. mDragLayout.setDragPositionListener(new DragSlopLayout.OnDragPositionListener() {  
  2.             @Override  
  3.             public void onDragPosition(int visibleHeight, float percent, boolean isUp) {  
  4.                 // TODO  
  5.             }  
  6.         });  

本站资源仅限于学习研究,严禁从事商业或者非法活动! 源码搜藏网所有源码来自互联网转载与用户上传分享,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!

布局类Layouts下载排行

最新文章