Android eventually officially supports setting the width of the control by a percentage.
Let's start by looking at the effect:
look at the layout:
Percentrelativelayout
<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 "> <view android:id=" @+id/top_left "android:layout_width=" 0DP "android:layou t_height= "0DP" android:layout_alignparenttop= "true" android:background= "#ff44aacc" App:layout_heig Htpercent= "20%" app:layout_widthpercent= "70%"/> <view android:id= "@+id/top_right" Andro Id:layout_width= "0DP" android:layout_height= "0DP" android:layout_alignparenttop= "true" Android:lay out_torightof= "@+id/top_left" android:background= "#ffe40000" app:layout_heightpercent= "20%" App:la yout_widthpercent= "30%"/> <view android: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>
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" > <!--... XML CODE--</android.support.percent.PercentFrameLayout>
Stylable:
- Heightpercent
- Widthpercent
- Marginbottompercent
- Marginendpercent
- Marginleftpercent
- Marginpercent
- Marginrightpercent
- Marginstartpercent
- Margintoppercent
Support:
- Android SDK V22
- Android Build Tools v22.0.1
- Android Percent Support Repository v22.2.0
- Android Support V4 Repository v22.2.0
according to the manifest Minsdk is V7 (Android 2.1)
GitHub Address: https://github.com/JulienGenoud/-support-lib-samplewebsite Description: https://juliengenoud.github.io/a ... support-lib-sample/
Android percentrelativelayout support percentage to set the control's width height