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.
DeleteGreat Article
Deleteandroid based projects
Java Training in Chennai
Project Center in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai
Its 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
https://tellthebellz.info/ food quality.
ReplyDeletehttps://tellthebellz.info/ food reviews.
ReplyDeletei 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.
ReplyDeleteMy engagement ring is platinum and I couldn't be happier. It is so shiny however the downside is that it's pretty expensive and costs more to size than gold. There are scratches although not very noticeable seaport hack
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.
ReplyDeleteGastroenterologist
Your jewelry is amazing. These could be used for embellishments for other craft items as well. Great ideas. horse riding tales hack
ReplyDeleteThe article was up to the point and described the information very effectively. Thanks to blog author for wonderful and informative post.
ReplyDeletetell the bell
The article was up to the point and described the information very effectively. Thanks to blog author for wonderful and informative post.
ReplyDeletekrogerfeedback
Greatpeople made an Online Employee Portal named Feed Kroger Login Portal or Website and in order to perform the sign in or log in, you need to open the official website URL which is Feed.Kroger.com on any of your favorite browser.
ReplyDeleteBuy Modafinil Online at your door step from one & only trusted pharma in this ERA. Buying Modafinil 100mg with Credit card.
ReplyDeleteFor 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.
ReplyDeleteHiTech FM is a home maintenance company in Dubai that offers services across all trade disciplines, including Cleaning, Plumbing, Electrical, Carpentry, Painting, Tiling, Air Conditioning, AC Servicing and more. We employ only expert tradespeople, ensuring the highest quality service. matter what your maintenance requirements. We are the best in Home & Office Maintenance Services in UAE.
ReplyDeleteThe article was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents.
ReplyDeleteby cognex is the AWS Training in chennai