Last Updated: August 30, 2015

Android percent support lib sample

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.

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 :-)

59 comments :

  1. hello,if i am using relative layout inside relative layout it is not working with percent
    here is my code -:







    ReplyDelete
    Replies
    1. @Abhishek Shrivastava I guess your code snippet got truncated. Please paste again.

      Delete
  2. Its open source nature makes it easier for device manufacturers to customize Android according to their specific needs. check here

    ReplyDelete
  3. Thanks 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.
    Kroger experience

    ReplyDelete
  4. 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.
    https://tellthebelll.us

    ReplyDelete
  5. Thanks for providing recent updates regarding the concern, I look to read more.
    Kroger customer survey

    ReplyDelete
  6. The blog and data is excellent and informative as well

    showboxappguide.com

    ReplyDelete
  7. dubsmash apk
    Hi! 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!

    ReplyDelete
  8. i really like this article please keep it up.
    check here

    ReplyDelete
  9. 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!
    https://www-expresshr.us/

    ReplyDelete
  10. 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.
    https://wvw-greatpeople.me/

    ReplyDelete
  11. 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
    UPS employee portal

    ReplyDelete
  12. 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
    seo tools

    ReplyDelete
  13. 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.
    survey monkey usa

    ReplyDelete
  14. I really thank you for the valuable info on this great subject and look forward to more great posts data loggers

    ReplyDelete
  15. this is a very good site and also visit this site watch latest movies and tv shows online for free without any credit card.
    showbox.apk

    ReplyDelete
  16. i see you got really very useful topics, i will be always checking your blog thanks. mobdro all streams offline

    ReplyDelete
  17. A great services provider with quality and low prices, without any visit you can take your services just by contact us.
    ac maintenance in dubai
    ac service in dubai

    ReplyDelete
  18. 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.

    ReplyDelete
  19. OMGGG...I am surprised to see thik horse riding tales hack thanks for the effort you ppl take to get this resources.

    ReplyDelete
  20. They seem to be easy but infact requires a lot of time and hardwork . Great work world of tanks blitz hack

    ReplyDelete
  21. The article was up to the point and described the information very effectively. Thanks to blog author for wonderful and informative post.
    krogerfeedback

    ReplyDelete
  22. 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.

    ReplyDelete
  23. Handyman 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.

    ReplyDelete
  24. These are some great tools that i definitely use for SEO work. This is a great list to use in the future..
    mcdvoicee.site

    ReplyDelete
  25. By sending refreshes about proposals on your business applications, you can permit clients to make buys effectively and quicker, at whenever and from anyplace. TutuApp web

    ReplyDelete
  26. https://www.coderconsole.com/2015/08/android-percent-support-lib-sample.html

    ReplyDelete
  27. his is very useful and it is is a great share!! Brawlhalla Mobile Hack

    ReplyDelete
  28. This one is good. Keep up the good work I also visit here: and I get lot of information.greatpeople Employee

    ReplyDelete
  29. 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

    ReplyDelete
  30. This 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

    ReplyDelete
  31. Thanks 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

    ReplyDelete
  32. Nicely… 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
    But wanna tell that this is invaluable , Thanks for taking your time to write this.ythub.cc

    ReplyDelete
  33. 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!

    How 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.

    ReplyDelete
  34. 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

    ReplyDelete
  35. 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 😀

    ReplyDelete
  36. Do 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

    ReplyDelete
  37. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. is nftshifter legit

    ReplyDelete
  38. Best Places To Bet On Boxing - Mapyro
    Where 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
  39. Thank you so much for sharing this great blog. Very inspiring and helpful too.

    Are 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!

    ReplyDelete
  40. 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

    ReplyDelete
  41. Incredible blog here! It's mind boggling posting with the checked and genuinely accommodating data. Pokemon Ash Ketchum Vest

    ReplyDelete
  42. A home buying guide for first-time buyers with current information and calculators and every step of the buying process. Buying Home in Canada

    ReplyDelete
  43. A home buying guide for first-time buyers with current information and calculators and every step of the buying process. Buying Home in Canada

    ReplyDelete
  44. It was not first article by this author as I always found him as a talented author. Tom Hardy Venom 2 Varsity Jacket

    ReplyDelete
  45. Thank you for sharing this content. I love to read this content. I have learn many difficult thing. hire a hacker

    ReplyDelete
  46. 세종 출장샵
    제주 출장샵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

Your comments are valuable for us !!!