AndroidStudio 中我们要用到PercentRelativeLayout的话首先要在build.gradle文件中添加一行代码
为
compile 'com.android.support:percent:23.1.0'或
dependencies {
compile 'com.android.support:percent:22.2.0'
}。
在xml文件中添加
<?xml version="1.0" encoding="utf-8"?> <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"> <TextView android:layout_width="0dp" android:layout_height="0dp" android:layout_gravity="bottom" android:background="#770000ff" android:text="width:100%,height:10%" android:gravity="center" app:layout_heightPercent="10%" app:layout_widthPercent="100%"/> </android.support.percent.PercentFrameLayout>
以上的出现的“%”是相对于整个看到的Activity而言