加入依赖
compile 'com.android.support:percent:26.+'布局
<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="zhaodongliang.view.Main2Activity"> <Button app:layout_widthPercent="50%" app:layout_heightPercent="50%" android:text="Button" android:textAllCaps="false" android:id="@+id/button_1" android:layout_gravity="left|top" /> </android.support.percent.PercentFrameLayout>