5秒让你的View变3D,ThreeDLayout使用和实现

在很久很久以前,写了一篇自定义3d view的博客。但是只是讲了如何实现,实现起来还是比较耗时,所以本着平易近人的心态,把他封装成了一个ViewGroup,只需要在你的view或者布局外面包裹一层ThreeDLayout 即可实现3D效果(毕竟:没有什么比拿来就能用更爽的事情了!!)。

ThreeDLayout的项目地址:https://github.com/githubwing/ThreeDLayout

效果预览

3D触摸效果,旋转效果,和用旋转效果实现的特效

这里写图片描述这里写图片描述这里写图片描述

如何导入ThreeDLayout

方式一

~~在gralde下加入compile(‘com.wingsofts.threedlayout:1.0.0’)~~(还没上传到远程仓库,会于近日上传)

方式二

将项目地址依赖库 :threedlayout文件夹下ThreeDLayout.java拷贝至你的项目中,即可使用。

如何使用

以Demo中天气Activity为例。

在xml中加入一个TextView,来显示大温度,下面一个RecyclerView,来显示每天的温度。

这就是一个最基本的界面实现。如何让大温度显示旋转起来呢?只需要用ThreeDlayout将其包裹。

在代码中获取到该layout,并且设置触摸模式,即可实现:

接下来讲解item动画实现,可以看到其实item是一个接一个延迟旋转,在ThreeDLayout中提供了翻转动画的方法:

所以Item动画其实是一个for循环,让他们依次执行动画即可~~(当然item要使用ThreeDLayout包裹):

### 到这里,ThreeDLayout的使用已经介绍完了,是不是很简单呢。如果你感兴趣,可以继续往下阅读,会介绍ThreeDLayout是如何实现的。

ThreeDLayout如何实现

在很久的一篇博客里,我介绍了如何实现一个3Dview,这里就不重复讲解。手把手带你撸一个3D view

这里主要讲解如何把每次都要写的代码封装起来。 我的初始思路就是直接包裹成一个ViewGroup,重写onDraw()方法即可。= = 没错就是这么简单。

所以我把之前3D view的代码搬运过来了,然后重写了一下onDraw()。

大概是这样就能完成3D的效果了,但是运行起来没卵用。因为viewgroup的onDraw()一般是不会调用的。怎么解决呢?其实让viewgroup参与draw的过程就好啦,于是我在构造器里给他添加了个背景色。有了背景色他就会调用onDraw了。

不过事情没有这么简单,还要解决测量问题,于是这里我就取巧,让ThreeDLayout只有一个子view,这样就可以把大小设置成子view的大小,免去测量的过程,所以onMeasure()是这样的:

为了提供不同的需求,所以扩展一下,用户可以自己设置是否开启触摸模式,并且可以设置X,Y,所以在onDraw()里进行一些判断:

现在一个ThreeDLayout就完成了。可是为了让他更好用呢,要添加一个动画效果,就是水平翻转动画,这样实用性更高,就可以实现天气Activity类似效果。所以在onDraw()里要多加一层旋转角度控制.

然后提供一个动画开始的方法,顺便当动画完成的时候,使degree变为0,这样就会处于不翻转状态:

然后再提供一个延迟动画的方法,内部开一个线程计时,然后去执行动画方法即可:

好啦,大功告成,以上就是ThreeDLayout的实现啦,如果你觉得效果比较cool,或者该控件比较实用,欢迎star一下~ 如果你喜欢我的博客,欢迎评论以及关注我~
ThreeDLayout的项目地址:https://github.com/githubwing/ThreeDLayout

5秒让你的View变3D,ThreeDLayout使用和实现》有63个想法

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

  2. I just want to say I am just new to blogging and site-building and absolutely loved you’re web page. Almost certainly I’m want to bookmark your blog . You absolutely have perfect article content. Regards for sharing with us your blog.

  3. I just wanted to type a quick message in order to appreciate you for the awesome ways you are writing at this site. My prolonged internet search has finally been compensated with excellent facts and strategies to write about with my two friends. I ‘d repeat that most of us site visitors actually are really endowed to exist in a fantastic community with so many lovely individuals with insightful hints. I feel very much grateful to have seen the weblog and look forward to many more thrilling minutes reading here. Thanks a lot again for all the details.

  4. I just wanted to jot down a quick message so as to say thanks to you for some of the lovely guides you are giving out at this site. My incredibly long internet investigation has now been compensated with useful information to write about with my company. I ‘d tell you that we readers actually are undoubtedly fortunate to exist in a useful website with very many wonderful professionals with beneficial opinions. I feel pretty grateful to have encountered the web pages and look forward to some more thrilling moments reading here. Thanks a lot once more for all the details.

  5. I definitely wanted to post a comment in order to appreciate you for those remarkable advice you are showing at this site. My long internet search has at the end been compensated with useful points to go over with my colleagues. I would assume that many of us site visitors actually are truly fortunate to exist in a very good website with very many awesome people with helpful opinions. I feel truly blessed to have come across your entire web page and look forward to tons of more fun minutes reading here. Thanks a lot again for all the details.

  6. I have to express some thanks to this writer for bailing me out of this crisis. After exploring throughout the world wide web and meeting ideas which were not productive, I figured my life was gone. Being alive without the presence of answers to the difficulties you’ve resolved all through the article is a serious case, as well as ones which could have negatively damaged my career if I had not noticed the website. Your good understanding and kindness in controlling all the stuff was crucial. I’m not sure what I would’ve done if I had not discovered such a stuff like this. It’s possible to at this moment relish my future. Thanks very much for your professional and result oriented help. I will not be reluctant to recommend your web sites to any person who ought to have tips on this topic.

  7. I precisely wanted to thank you very much again. I am not sure the things I could possibly have done in the absence of the type of information revealed by you regarding such a situation. It had been an absolute traumatic condition in my circumstances, but considering your expert technique you dealt with that took me to jump over happiness. I’m just happy for the service as well as sincerely hope you recognize what a great job you are always putting in instructing the rest via your website. More than likely you haven’t got to know all of us.

  8. I want to show my appreciation for your kind-heartedness supporting people that need help on this concern. Your special dedication to getting the solution all over appeared to be surprisingly insightful and has regularly allowed most people just like me to get to their ambitions. Your entire informative report means much a person like me and somewhat more to my colleagues. Many thanks; from everyone of us.

  9. I happen to be commenting to let you know of the great experience my daughter encountered studying your site. She realized plenty of details, which include what it is like to possess an awesome giving character to have others without hassle understand certain complicated subject areas. You really did more than readers’ desires. Thank you for producing the warm and helpful, trusted, edifying not to mention cool tips about this topic to Mary.

  10. Good day! I know this is kinda off topic nevertheless I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog article or vice-versa? My website covers a lot of the same subjects as yours and I think we could greatly benefit from each other. If you might be interested feel free to send me an email. I look forward to hearing from you! Wonderful blog by the way!

  11. I’m commenting to let you be aware of what a extraordinary discovery my wife’s girl developed studying your site. She learned a lot of pieces, most notably what it is like to possess a great giving nature to make others really easily have an understanding of certain tortuous issues. You really exceeded my expectations. Many thanks for presenting the important, dependable, edifying and fun thoughts on the topic to Emily.

  12. The URL is needed to figure out the security zone, which is needed to ascertain the condition of the ActiveScripting setting. Completely ad-free, this website is quite easy to navigate and enables you to locate what you need fast. It’s a website that will permit you to really observe plenty of svg files created by very talented people at an affordable price. Everyone can join and add to the undertaking. This facility is known as SVG fonts.

  13. I intended to draft you this tiny note just to say thanks as before about the breathtaking strategies you have featured on this site. It is certainly pretty open-handed of you to grant unreservedly exactly what some people could possibly have offered for sale as an e book to help make some cash for themselves, specifically since you could have done it in case you decided. The creative ideas also worked to become a easy way to comprehend most people have similar zeal similar to mine to understand significantly more when it comes to this matter. Certainly there are many more enjoyable instances up front for many who scan your blog.

  14. I am writing to let you be aware of of the impressive encounter my cousin’s child gained visiting your site. She came to find several details, which include what it’s like to have an ideal teaching mood to make men and women without hassle learn chosen tricky things. You undoubtedly exceeded visitors’ desires. Thank you for imparting such priceless, trusted, educational and unique guidance on that topic to Lizeth.

  15. I just desire to tell you that I am new to posting and utterly loved your post. Very possible I am going to save your blog post . You indeed have excellent article blog posts. Acknowledge it for giving out with us your web webpage

  16. Youre so cool! I dont suppose Ive learn something like this before. So good to search out someone with some original thoughts on this subject. realy thanks for starting this up. this website is something that is wanted on the web, somebody with just a little originality. useful job for bringing one thing new to the internet!

  17. I would like to voice my passion for your generosity in support of men and women that should have guidance on the niche. Your real dedication to passing the solution across came to be extraordinarily practical and have in most cases allowed associates just like me to attain their endeavors. Your amazing insightful help means so much a person like me and much more to my fellow workers. Thanks a lot; from all of us.

  18. I needed to send you one tiny observation so as to give many thanks as before with the marvelous concepts you’ve featured on this page. It was certainly extremely open-handed of people like you to supply easily all some people would have offered as an e book to get some profit for themselves, specifically now that you might well have done it in the event you considered necessary. The tricks likewise served to provide a great way to be certain that the rest have the identical passion just like mine to understand much more related to this problem. Certainly there are numerous more fun occasions ahead for individuals that examine your website.

  19. Wonderful goods from you, man. I have understand your stuff previous to and you’re just too wonderful. I really like what you have acquired here, certainly like what you’re stating and the way in which you say it. You make it entertaining and you still take care of to keep it smart. I can’t wait to read much more from you. This is really a tremendous website.

  20. I do consider all the ideas you have introduced to your post. They are really convincing and will definitely work. Still, the posts are very quick for starters. Could you please lengthen them a bit from next time? Thanks for the post.

  21. It is the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you some interesting things or advice. Perhaps you could write next articles referring to this article. I wish to read even more things about it!

  22. What i don’t understood is actually how you are now not really a lot more smartly-favored than you might be now. You’re so intelligent. You know thus significantly on the subject of this subject, made me individually imagine it from numerous various angles. Its like men and women don’t seem to be fascinated unless it is one thing to do with Girl gaga! Your individual stuffs nice. Always deal with it up!

  23. Good blog! I really love how it is simple on my eyes and the data are well written. I am wondering how I could be notified whenever a new post has been made. I’ve subscribed to your feed which must do the trick! Have a great day!

  24. Thanks a lot for giving everyone an extraordinarily terrific chance to read articles and blog posts from this blog. It’s usually so awesome and also stuffed with a great time for me and my office fellow workers to search your website at least thrice every week to read the latest stuff you have. And lastly, I am also certainly impressed for the unbelievable techniques served by you. Some 2 areas in this post are definitely the most effective we’ve ever had.

  25. I really want to notify you that I am new to having a blog and pretty much adored your webpage. Very likely I am probably to save your blog post . You really have excellent article content. Appreciate it for swapping with us the best website document

  26. I simply need to tell you that I am new to writing and absolutely loved your site. Quite possibly I am inclined to save your blog post . You literally have fantastic article blog posts. Like it for telling with us your own domain page

  27. It’s suitable opportunity to construct some schemes for the future. I’ve go through this article and if I have the ability to, I desire to recommend you some entertaining tips.

  28. Good site! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified when a new post has been made. I have subscribed to your RSS which must do the trick! Have a great day!

  29. I merely want to inform you you that I am new to blog posting and thoroughly adored your article. Quite possibly I am most likely to bookmark your blog post . You definitely have magnificent article information. Appreciate it for expressing with us your very own internet write-up

  30. My husband and i have been now satisfied when Jordan managed to carry out his basic research via the precious recommendations he was given using your web pages. It’s not at all simplistic to simply continually be giving freely tricks which men and women could have been selling. Therefore we discover we need the writer to give thanks to for this. These illustrations you’ve made, the easy blog menu, the friendships you help engender – it is all astounding, and it’s really making our son and our family reckon that this situation is enjoyable, and that’s pretty essential. Thanks for all!

  31. I want to express thanks to this writer for rescuing me from such a dilemma. Just after looking out through the the web and finding principles which were not powerful, I believed my life was over. Existing minus the solutions to the difficulties you’ve resolved through the guide is a serious case, as well as the kind which might have in a wrong way affected my career if I had not come across your blog. Your personal understanding and kindness in touching every item was helpful. I’m not sure what I would’ve done if I hadn’t encountered such a solution like this. It’s possible to now look ahead to my future. Thanks for your time very much for your expert and result oriented guide. I will not be reluctant to refer the sites to anybody who ought to have guidelines about this subject matter.

  32. Wonderful beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog website? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept

  33. Good site! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified whenever a new post has been made. I’ve subscribed to your RSS feed which must do the trick! Have a nice day!

  34. Wonderful beat ! I wish 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 concept

  35. I like what you guys are up also. Such intelligent work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my site :).

  36. Good web site! I truly love how it is easy on my eyes and the data are well written. I’m wondering how I could be notified whenever a new post has been made. I’ve subscribed to your feed which must do the trick! Have a great day!

  37. I wanted to draft you a little bit of observation in order to give thanks once again relating to the great ideas you have shown here. This is pretty open-handed with you to supply openly what exactly a lot of folks could have distributed for an e-book to end up making some money for themselves, certainly now that you could possibly have tried it in the event you decided. The secrets in addition served like the easy way to know that someone else have the identical fervor much like mine to find out much more on the topic of this problem. I am certain there are lots of more enjoyable moments ahead for those who discover your blog.

  38. You could definitely see your skills within the paintings you write. The world hopes for more passionate writers such as you who aren’t afraid to mention how they believe. All the time follow your heart.

  39. Thanks for sharing excellent informations. Your site is so cool. I am impressed by the details that you¡¦ve on this blog. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched everywhere and simply couldn’t come across. What a perfect web site.

  40. A person essentially assist to make severely articles I’d state. That is the first time I frequented your website page and thus far? I amazed with the research you made to create this actual post amazing. Fantastic process!

  41. of course like your website but you need to take a look at the spelling on quite a few of your posts. Several of them are rife with spelling problems and I to find it very bothersome to tell the reality however I’ll surely come again again.

  42. I precisely needed to appreciate you all over again. I do not know the things I would have followed without the methods shared by you over such a area of interest. It truly was the hard concern in my circumstances, nevertheless looking at your professional fashion you handled the issue forced me to weep over fulfillment. Extremely grateful for the support and hope you know what an amazing job you are always accomplishing instructing many others all through a web site. Most likely you haven’t come across any of us.

发表评论

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