Update:
From API Level 26, percent support library is deprecated. Please use updated code and samples from Github project.
GitHub project HERE
In this post I'm gonna show you guys a demo of percent layout of android from support library. Since many a time in our awesome RelativeLayout we insert LinearLayout just to get the property of layout_weight for accessing.Now android has a new support library to remove this dependencies.
Before beginning some pre-requestic (at the time for development):
- Android SDK v22
- Android Build Tools v22.0.1
- Android Percent Support Repository v23.0.0
- Android Support appcompat-v7:22.2.1
So let's get started:
Step 1: Add below line into apps build.gradle.
compile 'com.android.support:percent:23.0.0'
Step 2: Add any one of below as the parent of the layout.Its similar to our RelativeLayout or FrameLayout.
<android.support.percent.PercentRelativeLayout>or
<android.support.percent.PercentFrameLayout>
Step 3: Now we gonna use layout_heightPercent and layout_widthPercent property's to specify our height and width in percentage.
Consider this simple layout.
Consider this simple layout.
percent_layout.xml |
Lets make it :-)
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/fifty_fifty_tv" android:layout_width="0dp" android:layout_height="0dp" android:layout_gravity="center_horizontal" android:background="#ffff8800" android:text="50% - 50%" android:textColor="@android:color/white" android:textSize="25sp" app:layout_heightPercent="50%" app:layout_widthPercent="50%" /> <TextView android:id="@+id/twenty_fifty_tv" android:layout_width="0dp" android:layout_height="0dp" android:layout_gravity="center_horizontal" android:layout_toRightOf="@id/fifty_fifty_tv" android:background="#ffff5566" android:text="20%-50%" android:textSize="25sp" app:layout_heightPercent="20%" app:layout_widthPercent="50%" /> <TextView android:id="@+id/thirty_fifty_tv" android:layout_width="0dp" android:layout_height="0dp" android:layout_below="@id/twenty_fifty_tv" android:layout_gravity="center_horizontal" android:layout_toRightOf="@id/fifty_fifty_tv" android:background="#aa3628cc" android:text="30%-50%" android:textSize="25sp" app:layout_heightPercent="30%" app:layout_widthPercent="50%" /> <TextView android:id="@+id/century_50_tv" android:layout_width="0dp" android:layout_height="0dp" android:layout_below="@id/fifty_fifty_tv" android:layout_gravity="center_horizontal" android:background="#aacacc46" android:text="50%-100%" android:textSize="25sp" app:layout_heightPercent="50%" app:layout_widthPercent="100%" /> </android.support.percent.PercentRelativeLayout>
Thus by using the android percent support library we have made our layout simple by removing boilerplate layout.
GitHub project HERE
Really awesome :-)
hello,if i am using relative layout inside relative layout it is not working with percent
ReplyDeletehere is my code -:
@Abhishek Shrivastava I guess your code snippet got truncated. Please paste again.
DeleteIts open source nature makes it easier for device manufacturers to customize Android according to their specific needs. check here
ReplyDeleteGet the free version https://dpcwatchdogviolation.info
ReplyDeleteThanks for the nice blog. It was useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post.
ReplyDeleteKroger experience
I like this post,And I guess that having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
ReplyDeletehttps://tellthebelll.us
Thanks for providing recent updates regarding the concern, I look to read more.
ReplyDeleteKroger customer survey
The blog and data is excellent and informative as well
ReplyDeleteshowboxappguide.com
dubsmash apk
ReplyDeleteHi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job!
i really like this article please keep it up.
ReplyDeletecheck here
thanks this is good blog.
ReplyDeletenext page
I really loved reading your blog. It was very well authored easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well!
ReplyDeletehttps://www-expresshr.us/
I was surfing net and fortunately across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information.
ReplyDeletehttps://wvw-greatpeople.me/
All the contents you mentioned in is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks
ReplyDeleteUPS employee portal
This is my first t e i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work
ReplyDeleteseo tools
This is the news I have been waiting for. My wife has been trying to get me to quit smoking for years. There is no way that I will be able to go cold turkey. If e-cigarettes are as harmless as puffing air, I don't think she will be opposed to a conversion.
ReplyDeletesurvey monkey usa
I really thank you for the valuable info on this great subject and look forward to more great posts data loggers
ReplyDeletethis is a very good site and also visit this site watch latest movies and tv shows online for free without any credit card.
ReplyDeleteshowbox.apk
i see you got really very useful topics, i will be always checking your blog thanks. mobdro all streams offline
ReplyDeleteA great services provider with quality and low prices, without any visit you can take your services just by contact us.
ReplyDeleteac maintenance in dubai
ac service in dubai
If you are looking for AC maintenance in dubai then we are the best maintenance services provider. For AC maintenance Dubai, there are many companies regarding the maintenance and repair of Air conditioners.
ReplyDeleteOMGGG...I am surprised to see thik horse riding tales hack thanks for the effort you ppl take to get this resources.
ReplyDeleteThey seem to be easy but infact requires a lot of time and hardwork . Great work world of tanks blitz hack
ReplyDeleteThe article was up to the point and described the information very effectively. Thanks to blog author for wonderful and informative post.
ReplyDeletekrogerfeedback
For AC Repair Dubai, ac maintenance, ac service in dubai, give us a call and our team with fully anti corona precautions will be at your place.
ReplyDeleteHandyman Dubai offers you a diverse range of repair and home maintenance services in Dubai. A handyman is more efficient than you think if you hire a professional from us. Whether it is your apartment, villa, office, factory, or warehouse we have extended our reach anywhere in Dubai.
ReplyDeleteThis blog is truly splendid.
ReplyDeletekrogerfeedback
These are some great tools that i definitely use for SEO work. This is a great list to use in the future..
ReplyDeletemcdvoicee.site
https://www.coderconsole.com/2015/08/android-percent-support-lib-sample.html
ReplyDeletehis is very useful and it is is a great share!! Brawlhalla Mobile Hack
ReplyDeleteThis one is good. Keep up the good work I also visit here: and I get lot of information.greatpeople Employee
ReplyDeleteAivivu đại lý vé máy bay, tham khảo
ReplyDeletegiá vé máy bay đi Mỹ khứ hồi
bay về việt nam từ mỹ
lich bay tu duc ve viet nam
dịch vụ vé máy bay tại nga
giá vé máy bay từ anh về việt nam
lịch bay từ pháp về việt nam
Its an incredible joy perusing your post.Its brimming with data I am searching for and I want to post a remark that "The substance of your post is magnificent" Great work. Hacker for Phone Monitoring Services
ReplyDeleteThis is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.organization name
ReplyDeleteThanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me. 22bet download
ReplyDeleteNicely… to be absolutely genuine, My partner and i had not been hoping to stumble upon this kind of data accidentally, as I did, because I recently came across your blog article whilst I used to be the truth is running looking throughout AOL, looking for some thing very close up however, not a similar… On the other hand at this time I will be over happy for being here and also I want to bring that the insight is extremely intriguing even though a little bit controversial to the recognized… I’d personally say it’s as much as discussion… but I’m frightened to cause you to an opponent, ha, ha, ha… However, for those who like to dicuss at length over it, you need to response to my remark and also I will always sign up so that I’ll be informed and are available back again for much more… Your current hopeful friend
ReplyDeleteBut wanna tell that this is invaluable , Thanks for taking your time to write this.ythub.cc
An Advance Youtube To Mp3 Converter To Convert/Download YouTube Videos to MP3 or MP4 Format Easily, Safe & Secure, and in High-Quality Mp3 files for free. YouTube To Mp3 Converter - Safe & Fast Youtube to Mp3 • No limit Best YouTube To Mp3 Converter - Fast, Free, No limit!
ReplyDeleteHow To Convert YouTube To MP3?
Copy The Desire YouTube Video Url You Want To Download.
Paste Youtube Video {Url / Link} In The Box To Get High-Quality Mp3 Audio Files.
Click the "Download" button and wait a few seconds.
Select a video format from the list and click the "Download" button.
Thanks for another wonderful post. Where else could anybody get that type of info in such an ideal way of writing? ios application developer slc
ReplyDeleteNice Post!!
ReplyDeletePlease look here at Hire A Hacker Online
There’s some sort of mirror app you would get from trustedhackers.org it would enable you see what your significant other is up to without them knowing about it 😀
ReplyDeleteDo you have a feeling that your partner is seeing someone else? the first option is to ask your partner directly, If he/she keep denying and you have this strong feeling that he/ she is really cheating, then you have a lot on your plate to deal with I think it is very common for them to say no, even when they are, but saying no isn’t much of help about it, if someone is cheating on you behind you, it’s really because they don’t want you to because they want to have their cake and have it, or because they think of it as just a fling, or prohackerservice.com , who once did a great job for me when I was going through such difficulties.. cause they haven’t made their mind up whether to leave you or not or they are still trying to don't think you ought to wait around or trying all sort of apps before you have this done, as it might not work out and it might as well waste your time, you should talk to a professional & reliable hacker how to contact a professional hacker
ReplyDeleteBest Places To Bet On Boxing - Mapyro
ReplyDeleteWhere To หาเงินออนไลน์ Bet On Boxing. It's a sports betting filmfileeurope.com event in which you bet on the outcome of a game. In the boxing world, each player must decide if herzamanindir.com/ or not to 출장샵
폭스나인 폭스나인 폭스나인
ReplyDelete세종출장마사지 제주출장마사지 세귀포출장마사지
ReplyDeleteThank you so much for sharing this great blog. Very inspiring and helpful too.
ReplyDeleteAre you planning to develop an On-Demand fuel delivery app? get the full details about the on-demand fuel delivery app development cost, features & benefits. Contact us now!
Find the best Fixed mortgage rate in Kenora that work perfectly for you. We make it easy to compare rates in Kenora big banks and top brokers for free. Best mortgage rate in Kenora
ReplyDeleteI need a mortgage lender. I do you have? hire a hacker
DeleteIncredible blog here! It's mind boggling posting with the checked and genuinely accommodating data. Pokemon Ash Ketchum Vest
ReplyDeleteA home buying guide for first-time buyers with current information and calculators and every step of the buying process. Buying Home in Canada
ReplyDeleteA home buying guide for first-time buyers with current information and calculators and every step of the buying process. Buying Home in Canada
ReplyDeleteIt was not first article by this author as I always found him as a talented author. Tom Hardy Venom 2 Varsity Jacket
ReplyDeleteThank you for sharing this content. I love to read this content. I have learn many difficult thing. hire a hacker
ReplyDelete세종 출장샵
ReplyDelete제주 출장샵
서귀포 출장샵
전주 출장샵
김제 출장샵
세종 출장샵
ReplyDelete제주 출장샵
서귀포 출장샵
전주 출장샵
김제 출장샵
세종 출장샵
ReplyDelete제주 출장샵Find the best Fixed mortgage rate in Kenora that work perfectly for you. We make it easy to compare rates in Kenora big banks and top brokers for free
서귀포 출장샵
전주 출장샵
김제 출장샵
세종 출장샵
ReplyDelete제주 출장샵
서귀포 출장샵
세종 출장샵
ReplyDelete제주 출장샵
서귀포 출장샵
전주 출장샵
김제 출장샵