模仿iOS版微信的滑动View效果

前端之家收集整理的这篇文章主要介绍了模仿iOS版微信的滑动View效果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前言

最近经常交替使用Android和iOS手机。对于两个系统,从我们常用的列表来看,Android一般的列表菜单是通过长按出来的,而iOS是通过滑动出现的。比如我们常用的微信,对于Android版本,长按某个聊天好友,会弹出 标为未读,置顶聊天,删除聊天 选项;对于iOS的版本,右滑,会显示出 标为未读,删除 选项

---------------------------------我是分割线---------------------------------

1. 滑动View

1.1 内容展示

我在Android上面,实现了一个滑动的View,模仿的是微信的iOS版,先简单列举一下功能,直接上图,看着比较直观一些。下面我放了四个动画,分别是:滑动展开,单击,长按,双击。

滑动效果

模仿iOS版微信的滑动View效果


滑动展开

单击选择效果

模仿iOS版微信的滑动View效果


单击选择

长按、双击效果

模仿iOS版微信的滑动View效果


长按和双击效果

1.2 功能介绍

这个滑动View是一个自定义View,里面主要用了属性动画,触摸检测,触摸反馈,配合测量完成。

使用时,只需要在布局文件里面调用就可以,和 TextView 等常用控件一样,像这个样子。

在activity里面

  1. slideView = findViewById(R.id.slide_view1);
  2. slideView.setOnClickListener(new Listener.OnMenuClickListener() {
  3. @Override
  4. public void onClick(int id) {
  5. switch(id){
  6.  
  7. case R.id.menu_a:
  8. Util.toast("点击 删除");
  9. break;
  10. case R.id.menu_b:
  11. Util.toast("点击 设为未读");
  12. break;
  13. case R.id.sure_delete:
  14. Util.toast("点击 确认删除");
  15. break;
  16. case R.id.long_press:
  17. Util.toast("长按");
  18. VibratorLib.vibrateShort();
  19. break;
  20. case R.id.double_click:
  21. Util.toast("双击");
  22. break;
  23. }
  24. }
  25. });

在xml里面

  1. <android.support.constraint.ConstraintLayout
  2. ......
  3. <demo.com.library.view.SlideView
  4. android:id="@+id/slide_view1"
  5. ...
  6.  
  7. app:image_src="@drawable/crekerli_pig"
  8. app:image_margin_start="10dp"
  9. app:image_slide_length="60dp"
  10.  
  11. app:title_text="@string/title"
  12. app:title_text_size="20sp"
  13. app:title_text_color="@color/colorBlack"
  14. app:title_text_margin_start="10dp"
  15.  
  16. app:message_text="@string/message"
  17. app:message_text_size="12sp"
  18. app:message_text_color="@color/colorBlack"
  19. app:message_text_margin_start="10dp"
  20.  
  21. app:menu_a_background="@color/colorRed"
  22. app:menu_a_text="@string/delete"
  23. app:menu_a_text_size="20sp"
  24. app:menu_a_aspect="1"
  25.  
  26. app:menu_b_background="@color/colorGray"
  27. app:menu_b_text="@string/set"
  28. app:menu_b_text_size="20sp"
  29. app:menu_b_aspect="1.2"/>
  30. ...

从xml文件里面,细心一点儿可以看出我对SlideView的内容分成了 image title message menu_a menu_b 五个部分。对应到View里面,看下面的图示:

模仿iOS版微信的滑动View效果


页面展开前

模仿iOS版微信的滑动View效果


页面展开后

下面分别介绍一下五个部分。

2. 五个部分

2.1 image

image 表示用户头像,里面有三个配置参数

  1. app:image_src="@drawable/crekerli_pig"
  2. app:image_margin_start="10dp"
  3. app:image_slide_length="60dp"
  4. image_src
  5. image_margin_start
  6. image_slide_length

2.2 title

  1. app:title_text="@string/title"
  2. app:title_text_size="20sp"
  3. app:title_text_color="@color/colorBlack"
  4. app:title_text_margin_start="10dp"
  5. title_text
  6. title_text_size
  7. title_text_color
  8. title_text_margin_start

2.3 message

  1. app:message_text="@string/message"
  2. app:message_text_size="12sp"
  3. app:message_text_color="@color/colorBlack"
  4. app:message_text_margin_start="10dp"
  5. message_text
  6. message_text_size
  7. message_text_color
  8. message_text_margin_start

2.4 menu

menu_a 和menu_b的内容是一样的,所以这里放在一起统一讲

  1. app:menu_a_background="@color/colorRed"
  2. app:menu_a_text="@string/delete"
  3. app:menu_a_text_size="20sp"
  4. app:menu_a_aspect="1"
  5. app:menu_a_backgroundor
  6. app:menu_a_text
  7. app:menu_a_text_size
  8. app:menu_a_aspect

SlideView GitHub详细地址

总结

以上所述是小编给大家介绍的模仿iOS版微信的滑动View效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

猜你在找的iOS相关文章