First, you need to add the com.android.support:percent:24.1.1 package, the version is random.
dependencies { Compile filetree (dir: ' Libs ', include: [' *.jar ']) testcompile ' junit:junit:4.12 ' compile ' com.android.support:appcompat-v7:24.1.1 ' compile ' com.android.support:percent:24.1.1 '}
}
This package provides us with two layouts of percentrelativelayout and Percentframelayout,
The supported properties are layout_widthPercent , layout_heightPercent ,
layout_marginPercent, layout_marginLeftPercent ,
layout_marginTopPercent, layout_marginRightPercent ,
layout_marginBottomPercent, layout_marginStartPercent ,layout_marginEndPercent
That's probably what this is about, with a piece of code and
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.percent.percentrelativelayout xmlns:android= "http ://schemas.android.com/apk/res/android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height=" match_parent "xmlns:app=" Http://schemas.android.com/apk/res-auto "Tools:cont ext= "Com.example.administrator.mingyishijia.LoginActivity" > <android.support.v7.widget.toolbar xmlns:app= " Http://schemas.android.com/apk/res-auto "app:navigationicon=" @mipmap/left_back_gray_icon "android:id=" @+id/a Ctivity_main_toolbar "android:layout_height=" wrap_content "android:layout_width=" Match_parent "Androi d:minheight= "? attr/actionbarsize" android:background= "? Attr/colorprimary" ></ android.support.v7.widget.toolbar> <edittext android:layout_width= "0DP" android:layout_height= "0 DP "app:layout_heightpercent=" 8% "App:layout_widthpercent= "70%" android:background= "@drawable/usereditor_background" android:id= "@+id/username" Android:gravi ty= "center" android:layout_below= "@+id/activity_main_toolbar" app:layout_margintoppercent= "10%" Andro Id:layout_centerhorizontal= "true" android:hint= "Please enter account"/> <edittext android:layout_width= "0DP" android:layout_height= "0DP" app:layout_heightpercent= "8%" app:layout_widthpercent= "70%" Android:bac kground= "@drawable/usereditor_background" android:id= "@+id/password" android:layout_below= "@+id/userName" android:gravity= "center" app:layout_margintoppercent= "2%" android:layout_centerhorizontal= "true" android:hint= "Please enter password"/> <button android:layout_width= "0DP" android:layout_height= "0DP" app:l Ayout_heightpercent= "8%" app:layout_widthpercent= "70%" android:background= "@drawable/login_button_background "Android:id=" @+iD/login "android:layout_below=" @+id/password "android:text=" Login "android:textsize=" 18SP "an Droid:textcolor= "#ffffff" android:layout_centerhorizontal= "true" app:layout_margintoppercent= "5%"/> & Lt TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:id= "@+id/fo Rgetpassword "android:layout_below=" @+id/login "android:layout_alignleft=" @+id/login "App:layout_marg Intoppercent= "2%" android:text= "Forgot Password" android:textsize= "12SP" android:textcolor= "#1a81ff"/> < ; LinearLayout android:layout_width= "0DP" android:layout_height= "Wrap_content" app:layout_widthpercent= "90%" android:id= "@+id/l1" android:orientation= "Horizontal" android:clickable= "false" Android: Layout_centerhorizontal= "true" android:layout_below= "@+id/forgetpassword" app:layout_margintoppercent= "5%" &G T <view Android:layout_width= "Match_parent" android:layout_height= "1DP" android:background= "#00000 0 "android:layout_weight=" 1.1 "android:layout_gravity=" center "/> <textview A Ndroid:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_weight= "1" Android:text= "or use the following method to log in to" android:textsize= "12SP" android:gravity= "center"/> <v Iew android:layout_width= "match_parent" android:layout_height= "1DP" android:background= "# 000000 "android:layout_weight=" 1.1 "android:layout_gravity=" center "/> </LinearLayout> <linearlayout android:layout_width= "0DP" android:layout_height= "0DP" app:layout_heightpercent= "15 % "app:layout_widthpercent=" 75% "android:layout_centerhorizontal=" true "android:orientation=" Horizont Al "Android:layout_below= "@+id/l1" app:layout_margintoppercent= "5%" android:id= "@+id/linearlayout" > <android.sup Port.percent.PercentRelativeLayout android:layout_width= "match_parent" android:layout_height= "Match_ Parent "android:layout_weight=" 1 "> <imageview android:layout_width=" 0DP " android:layout_height= "0DP" app:layout_heightpercent= "60%" app:layout_widthpercent= "100%" android:scaletype= "Fitcenter" android:id= "@+id/iv1" android:src= "@mipm Ap/weixin "/> <textview android:layout_width=" 0DP "android:layout_height=" 0d P "app:layout_heightpercent=" 40% "app:layout_widthpercent=" 100% "Android:layo ut_below= "@+id/iv1" android:text= "android:gravity=" center "/> </android.suppor T.percent.percentrelativelayout> <android.support.percent.percentrelativelayout android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:layout_weight= "1" > <imageview Android:layout_width= "0DP" android:layout_height= "0DP" app:layout_heightpercent= "60%" App:layout_widthpercent= "100%" android:scaletype= "Fitcenter" android:id= "@+id/iv2" android:src= "@mipmap/aqq1"/> <textview android:layout_width= "0DP" android:layout_height= "0DP" app:layout_heightpercent= "40%" app:layout_widthpercent= "1 00% "android:layout_below=" @+id/iv2 "android:text=" QQ "android:gravity=" Cente R "/> </android.support.percent.PercentRelativeLayout> <android.support.percent.percentrelativela Yout Android:Layout_width= "Match_parent" android:layout_height= "Match_parent" android:layout_weight= "1" > <imageview android:layout_width= "0DP" android:layout_height= "0DP" AP P:layout_heightpercent= "60%" app:layout_widthpercent= "100%" android:scaletype= "Fitcenter" Android:id= "@+id/iv3" android:src= "@mipmap/dingding"/> <textv Iew android:layout_width= "0DP" android:layout_height= "0DP" APP:LAYOUT_HEIGHTP Ercent= "40%" app:layout_widthpercent= "100%" android:layout_below= "@+id/iv3" a ndroid:text= "Nail" android:gravity= "center"/> </android.support.percent.percentrelativelayout> ; </LinearLayout></android.support.percent.PercentRelativeLayout>
Android adaptation--percent adaptation