1.PercentRelativeLayout
在build.gradle添加依赖库:
implementation 'androidx.percentlayout:percentlayout:1.0.0'
代码解释:
xmlns:app="http://schemas.android.com/apk/res-auto" 添加一个app命名空间
<?xml version="1.0" encoding="utf-8"?>
<androidx.percentlayout.widget.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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:layout_alignParentBottom="true"
android:gravity="center"
android:textSize="20sp"
android:background="#FF1493"
android:textColor="#ffffff"
app:layout_widthPercent = "15%"
app:layout_heightPercent = "100%"
app:layout_marginPercent="4%"
android