Githup:https://github.com/juliengenoud/android-percent-support-lib-sample
Here's how to use it:
Android Percent Support Lib Sample
I made a sample of the new percent support library.
You can check official Docs reference here and here.
This library provide percentage based layouts, horizontal and vertical at the same time.
Simple result
Complex result
How to use:
Just add percent support library to your project
Dependencies { 'com.android.support:percent:25.3.0'}
# # #Supported Layouts:
# # #PercentRelativeLayout
<Android.support.percent.PercentRelativeLayoutxmlns: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"> <ViewAndroid:id= "@+id/top_left"Android:layout_width= "0DP"Android:layout_height= "0DP"Android:layout_alignparenttop= "true"Android:background= "#ff44aacc"app:layout_heightpercent= "20%"app:layout_widthpercent= "70%" /> <ViewAndroid:id= "@+id/top_right"Android:layout_width= "0DP"Android:layout_height= "0DP"Android:layout_alignparenttop= "true"Android:layout_torightof= "@+id/top_left"Android:background= "#ffe40000"app:layout_heightpercent= "20%"app:layout_widthpercent= "30%" /> <ViewAndroid:id= "@+id/bottom"Android:layout_width= "Match_parent"Android:layout_height= "0DP"Android:layout_below= "@+id/top_left"Android:background= "#ff00ff22"app:layout_heightpercent= "80%" /></Android.support.percent.PercentRelativeLayout>
# # #PercentLinearLayout
<Com.juliengenoud.percentsamples.PercentLinearLayoutxmlns: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"android:orientation= "vertical"> <ViewAndroid:layout_width= "0DP"Android:layout_height= "0DP"Android:background= "#ff44aacc"app:layout_heightpercent= "10%"app:layout_widthpercent= "60%"/> <ViewAndroid:layout_width= "0DP"Android:layout_height= "0DP"Android:background= "#ff4400cc"app:layout_heightpercent= "10%"app:layout_widthpercent= "70%"/></Com.juliengenoud.percentsamples.PercentLinearLayout>
# # #PercentFrameLayout
< android.support.percent.PercentFrameLayout 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"> <!-- -</android.support.percent.PercentFrameLayout>
Simple and clear.
Recommended Android layout percent frame