这交互炸了(四) :一分钟让你拥有微信拖拽透明返回PhotoView

《交互炸了》或许是一系列高端特效教程, 文中会介绍一些比较炫酷的特效,以及实现的思路。特效实现本身也许不会有太大的难度。难点在于实现的思路。一旦思路被打开,特效将很简单实现。

DragPhotoView项目地址https://github.com/githubwing/DragPhotoView

大家好,本期是交互炸了第四期~ 本期带来的效果是最新版微信朋友圈看图下拖的效果,没见过的赶紧去更新微信啦~~

本期跟以往不一样:

不是demo! 拿来直接用!不是demo! 拿来直接用!不是demo! 拿来直接用!重要说三你懂.

效果图如下:

自我感觉实现的效果还不错哈.猛地一看自己都以为他就是微信了哈哈.

一分钟使用方式:


修改你的 build.gradle文件

把它放到xml里

把它当成普通ImageView使用就行了,所有ImageView的玩法都可以在它身上玩.注意必须要加一个onExitListener,这是在拖拽出范围的监听.

这样就完成了接入,甚至比一分钟还快有没有!拒绝标题党.


上面讲解的是用法,可是用谁都会,使用一个三方库,都要了解实现对不? 下面就给大家介绍实现的思路.

实现

基于PhotoView

第一眼看到这个效果,就有想实现的冲动,因为使用场景挺多的感觉. 所以直接找来GitHub上star最多的PhotoView来进行扩展,这里我选择直接依赖并且继承PhotoView,理由是如果PhotoView出了更新,依赖直接改动版本即可.如果我选择源码copy的方式改动,那么将得不到PhotoView的支持.

图片缩放,背景透明

这里需要Activity配合,将背景设置为透明.并且背景实黑色的,为了配合手势改变View背景透明度,我绘制一个超大的矩形充当背景:

画布位移和缩放还有透明度都跟着手势变化而变化.所以要处理触摸事件,一开始我尝试重写onTouchEvent方法,发现并不生效,原因是PhotoView内部使用了自己的手势处理机制. 所以手势处理束手无策里吗? 非也,我们可以在dispatchTouchEvent做处理.所以重写该方法:

首先判断是否处于缩放模式,只有非缩放模式的时候才可以拖拽

之后处理ACTION_MOVE事件:
需要注意的是,要解决一下Viewpager和DragPhotoView和PhotoView的冲突.

DragPhotoView和PhotoView的冲突在于手势缩放,所以只要判断一下当前是几个触摸点即可.

下Viewpager和DragPhotoView冲突在左右滑,所以这里判断为:如果没有向下移动过,则Y位移为0交由ViewPager处理,如果向下移动过,则改变标志位说明正在处于拖拽状态

在ACTION_UP的时候,要判断一下是否拖拽超过阀值,如果超过了阀值则进行结束Activity操作.

这里遇到个坑就是,单指返回和双击放大手势冲突了.目前没有找到什么好的解决方法,只能开启线程计时来根据标志位判断,各位看官有好的解决方式,请联系告知我,谢谢!

这样基本上就完成了对PhotoView的扩展. 已经可以接入项目中使用了.

但是本文还没有完,下面说一下共享元素的全版本实现

Android自带的共享元素只有5.0以上才可以使用.那么怎么兼容到5.0以下呢.并且Demo中的拖拽共享是怎么实现的呢?

其实思路很简单,只需要在Activity A启动Activity B的时候,关闭系统专场动画,把被点击的View 大小,坐标等信息传入. B先为透明状态,把B上的View做一个位移动画,就可以实现了.

至于拖拽共享元素,原理是一样的,具体的细节就在demo中啦~~

本文到此就结束啦~

DragPhotoView项目地址https://github.com/githubwing/DragPhotoView

如果你觉得不错,欢迎Star,也可以加入我的Android酒馆:425983695

这交互炸了(四) :一分钟让你拥有微信拖拽透明返回PhotoView》有77个想法

  1. I was recommended this web site by my cousin. I am not certain whether this post is written via him as no one else recognise such designated about my difficulty.
    You are amazing! Thank you!

  2. I just want to tell you that I’m new to weblog and definitely loved you’re web-site. Most likely I’m want to bookmark your site . You definitely have fantastic stories. Regards for sharing with us your blog.

  3. I simply had to appreciate you once again. I do not know what I would’ve followed without the strategies shared by you over this industry. It had become a very terrifying situation in my opinion, however , seeing the specialised technique you treated the issue took me to leap for delight. I will be thankful for your help as well as believe you are aware of a powerful job you are always doing instructing many others using a site. I know that you’ve never got to know any of us.

  4. I am only writing to make you be aware of what a really good discovery my wife’s girl obtained reading through your blog. She came to understand lots of things, with the inclusion of how it is like to possess an amazing giving mindset to get the mediocre ones with no trouble know just exactly specific grueling subject areas. You actually exceeded her desires. I appreciate you for rendering the beneficial, dependable, explanatory as well as cool guidance on the topic to Tanya.

  5. I as well as my buddies have been reading the excellent key points found on your web blog then immediately I had a terrible feeling I had not thanked the site owner for those strategies. These boys were for that reason glad to read through them and now have in truth been tapping into those things. Many thanks for turning out to be indeed helpful and for using some helpful areas most people are really needing to discover. My personal sincere apologies for not expressing appreciation to you earlier.

  6. I wanted to make a small message to express gratitude to you for some of the pleasant recommendations you are showing at this website. My time-consuming internet lookup has finally been honored with pleasant facts and techniques to exchange with my companions. I would repeat that we readers actually are definitely fortunate to exist in a magnificent site with very many marvellous people with very helpful points. I feel very much blessed to have seen the web site and look forward to really more entertaining times reading here. Thank you again for all the details.

  7. I precisely had to say thanks all over again. I do not know what I might have worked on without the type of smart ideas provided by you on that area of interest. Entirely was a very distressing situation in my opinion, nevertheless understanding a new skilled technique you handled that made me to leap over happiness. I am just grateful for the work and as well , have high hopes you are aware of a powerful job you were accomplishing training the others through a site. More than likely you’ve never encountered any of us.

  8. I truly wanted to develop a brief note to appreciate you for the awesome steps you are writing on this website. My considerable internet research has at the end been rewarded with extremely good concept to write about with my friends and family. I would mention that many of us website visitors actually are undoubtedly endowed to live in a remarkable site with many special people with valuable guidelines. I feel extremely lucky to have encountered your web pages and look forward to tons of more entertaining minutes reading here. Thanks once more for everything.

  9. Needed to send you a very little remark in order to give many thanks as before for these marvelous secrets you have provided in this case. This has been incredibly generous of people like you to offer openly precisely what a lot of folks could have advertised for an e-book to make some dough for themselves, primarily considering that you might have tried it if you decided. Those good tips additionally worked as the easy way to fully grasp that many people have similar dream really like mine to realize a whole lot more when it comes to this matter. I think there are numerous more fun situations up front for people who find out your blog post.

  10. Thank you for all your valuable hard work on this website. My daughter really likes making time for investigation and it’s easy to understand why. A lot of people notice all relating to the powerful mode you render simple tactics via your blog and therefore encourage participation from visitors on this subject matter while our own princess has always been being taught so much. Take pleasure in the rest of the new year. Your performing a fabulous job.

  11. I must convey my affection for your generosity for folks that really want guidance on that study. Your very own commitment to passing the solution up and down ended up being surprisingly effective and have always encouraged people just like me to get to their objectives. Your interesting useful information means this much a person like me and even further to my peers. Warm regards; from all of us.

  12. I simply wanted to write down a small word to be able to appreciate you for all of the nice techniques you are sharing here. My extended internet lookup has now been recognized with professional concept to share with my classmates and friends. I ‘d claim that we visitors are definitely fortunate to be in a magnificent network with very many lovely individuals with very helpful plans. I feel somewhat fortunate to have come across your entire webpage and look forward to tons of more fabulous moments reading here. Thank you once more for all the details.

  13. I wish to express thanks to this writer for rescuing me from such a challenge. Just after looking through the world-wide-web and coming across tips that were not pleasant, I assumed my entire life was over. Being alive without the presence of answers to the problems you’ve resolved as a result of the report is a serious case, and those which might have adversely affected my career if I had not come across the website. Your personal training and kindness in dealing with all things was precious. I’m not sure what I would’ve done if I had not encountered such a step like this. I’m able to now relish my future. Thanks so much for the specialized and amazing guide. I will not think twice to recommend your blog post to anybody who needs support on this area.

  14. I merely hope to share it with you that I am new to writing a blog and genuinely cherished your information. Very possible I am likely to save your blog post . You undoubtedly have memorable article materials. Like it for sharing with us all of your website page

  15. It really is most suitable time to construct some plans for the long run. I’ve study this piece of writing and if I can possibly, I desire to suggest you couple of enlightening suggestions.

  16. All absolutely free clipart is created by an identical designer. Nowadays you know the best place to locate totally free clipart, you can save a good deal of Googling! AAA Clipart is a superb site on account of the substantial selection of completely free clipart images available there.

  17. I and also my guys were actually following the good information located on your web blog then immediately got a horrible feeling I had not expressed respect to the web blog owner for those strategies. All of the young boys happened to be absolutely excited to read all of them and already have in actuality been taking pleasure in them. I appreciate you for truly being very considerate and also for finding this sort of excellent tips most people are really eager to know about. Our own honest apologies for not expressing gratitude to earlier.

  18. I really wanted to write a message so as to say thanks to you for all the lovely tips and tricks you are giving on this site. My incredibly long internet investigation has at the end been recognized with professional strategies to exchange with my visitors. I would claim that we site visitors actually are really lucky to exist in a notable website with very many lovely professionals with beneficial plans. I feel really grateful to have come across your entire webpage and look forward to really more exciting times reading here. Thanks a lot again for everything.

  19. I actually wanted to write down a small comment to say thanks to you for the pleasant tips you are giving at this website. My considerable internet investigation has at the end been paid with reputable concept to talk about with my partners. I ‘d say that most of us site visitors actually are very lucky to be in a notable network with very many special professionals with helpful techniques. I feel extremely happy to have encountered your webpage and look forward to so many more amazing minutes reading here. Thanks a lot once more for a lot of things.

  20. A lot of thanks for your own hard work on this site. Kim take interest in engaging in investigation and it’s really easy to see why. A number of us notice all about the dynamic way you present efficient tips and tricks via your web blog and therefore attract contribution from other people on the subject and our child is really studying a lot. Take pleasure in the rest of the new year. You are always doing a brilliant job.

  21. Thanks a lot for providing individuals with an exceptionally nice chance to read critical reviews from this site. It can be so amazing and jam-packed with fun for me personally and my office mates to search your blog not less than three times in one week to find out the latest secrets you will have. And definitely, we are certainly motivated considering the striking tips and hints served by you. Some two tips in this posting are certainly the most efficient we’ve ever had.

  22. Excellent beat ! I would like to apprentice while you amend your website, how can i subscribe for a blog web site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear idea

  23. I remain in my late FIFTY’s as well as I can easily tell you that this mattress is actually the very most comfortable mattress I have actually ever before reconsidered. I anticipate creeping right into bedroom in the evening as well as I wake revitalized from a great night sleep.

  24. I would like to get across my affection for your generosity in support of folks who have the need for assistance with this important study. Your very own dedication to getting the solution across appeared to be exceptionally good and have continually permitted girls like me to reach their ambitions. This useful guidelines entails this much to me and much more to my colleagues. Thanks a ton; from each one of us.

  25. Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Anyway I’ll be subscribing to your augment and even I achievement you access consistently rapidly.

  26. I wish to convey my gratitude for your kindness giving support to people who require help on your idea. Your special commitment to passing the message throughout became certainly important and have continually enabled people like me to arrive at their objectives. Your personal helpful hints and tips denotes a lot to me and additionally to my office workers. Thanks a lot; from all of us.

  27. I just wish to reveal to you that I am new to online blogging and genuinely admired your review. Likely I am most likely to remember your blog post . You really have extraordinary article blog posts. Delight In it for swapping with us your url write-up

  28. I simply wanted to appreciate you once again. I do not know the things I would’ve done without those ideas contributed by you directly on my question. It became a very challenging circumstance for me, however , seeing your expert fashion you dealt with the issue took me to jump for joy. I will be thankful for this guidance and then believe you realize what a great job that you are doing educating people by way of a site. I am certain you’ve never met all of us.

  29. I do not even know how I ended up here, but I thought this post was good. I don’t know who you are but definitely you’re going to a famous blogger if you aren’t already 😉 Cheers!

  30. This is the best day to prepare some goals for the long-run. I’ve read through this post and if I have the ability to, I wish to suggest to you you number of important tip.

  31. I as well as my friends have been checking the best pointers found on your web blog and suddenly I got an awful suspicion I had not expressed respect to the blog owner for those techniques. All the ladies had been for that reason happy to study all of them and have in effect really been taking pleasure in them. Many thanks for being indeed thoughtful and also for settling on varieties of high-quality information most people are really needing to understand about. Our sincere apologies for not saying thanks to earlier.

  32. Hi folks there, just became alert to your blog site through The Big G, and discovered that it’s pretty helpful. I will appreciate if you carry on this post.

  33. I just have to show you that I am new to writing and pretty much admired your website. Likely I am inclined to save your blog post . You certainly have amazing article information. Like it for discussing with us your current internet site document

  34. I have not checked in here for some time because I thought it was getting boring, but the last several posts are good quality so I guess I¡¦ll add you back to my everyday bloglist. You deserve it my friend 🙂

  35. Attractive section of content. I just stumbled upon your web site and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently fast.

  36. hi!,I love your writing so much! percentage we be in contact more approximately your article on AOL? I require a specialist on this space to unravel my problem. Maybe that’s you! Looking ahead to peer you.

  37. hello there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise some technical issues using this web site, since I experienced to reload the site a lot of times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will often affect your placement in google and could damage your high-quality score if ads and marketing with Adwords. Well I’m adding this RSS to my e-mail and could look out for much more of your respective intriguing content. Ensure that you update this again soon..

  38. I precisely desired to thank you so much again. I am not sure the things I would have achieved in the absence of these strategies documented by you directly on such a field. It was a depressing difficulty in my position, but encountering a new skilled avenue you managed the issue forced me to weep over gladness. Now i’m thankful for the information as well as hope that you find out what a great job you have been undertaking educating men and women all through your blog. I am sure you haven’t met any of us.

  39. I intended to write you this very small remark in order to say thanks yet again for the awesome tactics you have discussed in this case. This is quite remarkably open-handed of people like you in giving without restraint exactly what a number of us could possibly have marketed as an e-book in making some dough for themselves, particularly seeing that you might well have done it if you ever considered necessary. Those creative ideas in addition served to become easy way to recognize that other individuals have the identical eagerness the same as my very own to see more and more with regards to this issue. I’m sure there are many more pleasant instances in the future for people who find out your site.

  40. Thanks , I have recently been searching for information about this subject for a long time and yours is the best I’ve discovered till now. But, what concerning the bottom line? Are you positive in regards to the supply?

  41. I¡¦ll right away grab your rss feed as I can’t in finding your email subscription link or e-newsletter service. Do you’ve any? Kindly permit me realize in order that I may subscribe. Thanks.

  42. Whats Going down i am new to this, I stumbled upon this I have found It positively useful and it has aided me out loads. I am hoping to give a contribution & aid other users like its helped me. Good job.

  43. Excellent beat ! I would like to apprentice while you amend your website, how can i subscribe for a blog web site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept

  44. Thank you so much for providing individuals with remarkably brilliant chance to read from here. It can be very excellent plus stuffed with fun for me personally and my office acquaintances to search the blog the equivalent of three times in a week to read through the latest guidance you have got. And indeed, I’m always contented with all the outstanding creative ideas served by you. Certain 3 areas in this post are unquestionably the best I’ve had.

  45. I’ve been browsing on-line greater than 3 hours as of late, yet I never discovered any attention-grabbing article like yours. It is beautiful value enough for me. In my view, if all webmasters and bloggers made just right content as you did, the internet will likely be a lot more helpful than ever before.

发表评论

电子邮件地址不会被公开。