添加支持库
dependencies {
compile 'com.android.support:percent:22.2.0'
}
支持的布局:
PercentRelativeLayout PercentFrameLayout
用法也很简单:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="click"
app:layout_heightPercent="10%"
app:layout_widthPercent="50%" />
</android.support.percent.PercentRelativeLayout>