一、使用 导库: implementation ‘androidx.percentlayout:percentlayout:1.0.0’
属性: app:layout_heightPercent:用百分比表示控件高度
app:layout_widthPercent:用百分比表示控件宽度
app:layout_marginPercent:用百分比表示View之间的间隔
app:layout_marginLeftPercent:用百分比表示左边间隔
app:layout_marginTopPercent:用百分比表示顶部间隔
app:layout_marginBottomPercent:用百分比表示底部间隔
app:layout_marginStartPercent:用百分比表示距离第一个View之间的距离
app:layout_marginEndPercent:用百分比表示距离最后一个View之间的距离
app:layout_aspectRatio:用百分比表示View的宽高比
二、布局 界面效果图: 
```java
```java
```java
```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.percentlayout.widget.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"
android:background="@mipmap/bg_home"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="健康"
android:textColor="@color/black"
android:textSize="30dp"
app:layout_heightPercent="8%"
app:layout_widthPercent="20%"
app:layout_marginLeftPercent="4%"
app:layout_marginTopPercent="2%"/>
<Button
android:id="@+id/xie_yang_btn"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="血氧"
android:textColor="@color/fff"
android:textSize="36sp"
android:background="@drawable/btn_background_xue_yang"
app:layout_heightPercent="41%"
app:layout_widthPercent="44%"
app:layout_marginLeftPercent="4%"
app:layout_marginTopPercent="10%"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/ic_xue_yang"
android:adjustViewBounds="true"
android:elevation="3dp"
app:layout_heightPercent="12%"
app:layout_widthPercent="15%"
app:layout_marginLeftPercent="18%"
app:layout_marginTopPercent="15%"
</ImageView>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="上次测量值:"
android:elevation="3dp"
android:textColor="@color/fff"
app:layout_heightPercent="5%"
app:layout_widthPercent="25%"
app:layout_marginLeftPercent="6%"
app:layout_marginTopPercent="36%"
/>
<TextView
android:id="@+id/xie_yang_shc_data"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="暂无数据"
android:elevation="3dp"
android:textColor="@color/fff"
android:textSize="36dp"
app:layout_heightPercent="11%"
app:layout_widthPercent="40%"
app:layout_marginLeftPercent="6%"
app:layout_marginTopPercent="40%"
/>
<Button
android:id="@+id/xin_lv_btn"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="心率"
android:textColor="@color/fff"
android:textSize="36dp"
android:background="@drawable/btn_background_xin_lv"
app:layout_heightPercent="41%"
app:layout_widthPercent="44%"
app:layout_marginLeftPercent="52%"
app:layout_marginTopPercent="10%"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/ic_xin_lv"
android:elevation="3dp"
app:layout_heightPercent="12%"
app:layout_widthPercent="15%"
app:layout_marginLeftPercent="66%"
app:layout_marginTopPercent="15%"
/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="上次测量值:"
android:elevation="3dp"
android:textColor="@color/fff"
app:layout_heightPercent="5%"
app:layout_widthPercent="25%"
app:layout_marginLeftPercent="55%"
app:layout_marginTopPercent="36%"
/>
<TextView
android:id="@+id/xin_lv_shc_data"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="暂无数据"
android:elevation="3dp"
android:textColor="@color/fff"
android:textSize="36dp"
app:layout_heightPercent="11%"
app:layout_widthPercent="40%"
app:layout_marginLeftPercent="55%"
app:layout_marginTopPercent="40%"
/>
<Button
android:id="@+id/ti_wen_btn"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="体温"
android:textSize="36dp"
android:textColor="@color/fff"
android:background="@drawable/btn_background_ti_wen"
app:layout_heightPercent="41%"
app:layout_widthPercent="44%"
app:layout_marginLeftPercent="4%"
app:layout_marginTopPercent="53%"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/ic_ti_wen"
android:elevation="3dp"
app:layout_heightPercent="12%"
app:layout_widthPercent="15%"
app:layout_marginLeftPercent="18%"
app:layout_marginTopPercent="58%"
/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="上次测量值:"
android:elevation="3dp"
android:textColor="@color/fff"
app:layout_heightPercent="5%"
app:layout_widthPercent="25%"
app:layout_marginLeftPercent="6%"
app:layout_marginTopPercent="80%"
/>
<TextView
android:id="@+id/ti_wen_shc_data"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="暂无数据"
android:elevation="3dp"
android:textColor="@color/fff"
android:textSize="36dp"
app:layout_heightPercent="11%"
app:layout_widthPercent="40%"
app:layout_marginLeftPercent="6%"
app:layout_marginTopPercent="83%"
/>
<Button
android:id="@+id/ji_bu_btn"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="记步"
android:textSize="36dp"
android:textColor="@color/fff"
android:background="@drawable/btn_background_ji_bu"
app:layout_heightPercent="41%"
app:layout_widthPercent="44%"
app:layout_marginLeftPercent="52%"
app:layout_marginTopPercent="53%"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/ic_ji_bu"
android:elevation="3dp"
app:layout_heightPercent="12%"
app:layout_widthPercent="15%"
app:layout_marginLeftPercent="66%"
app:layout_marginTopPercent="58%"
/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="上次测量值:"
android:elevation="3dp"
android:textColor="@color/fff"
app:layout_heightPercent="5%"
app:layout_widthPercent="25%"
app:layout_marginLeftPercent="55%"
app:layout_marginTopPercent="80%"
/>
<TextView
android:id="@+id/ji_bu_data"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00000000"
android:text="暂无数据"
android:elevation="3dp"
android:textColor="@color/fff"
android:textSize="36dp"
app:layout_heightPercent="11%"
app:layout_widthPercent="40%"
app:layout_marginLeftPercent="55%"
app:layout_marginTopPercent="83%"
/>
</androidx.percentlayout.widget.PercentFrameLayout>
三、层级问题 一般情况Button是会覆盖textview的,可以添加属性: android:elevation=“3dp” android:elevation=“2dp” 即可使textview展示在button层级上
四、字体大小,百分比大小修改 TextView控件带线已经可以按百分比算出来,但是字体尺寸没法确定 可以用这个属性: android:autoSizeTextType=“uniform” 字体自动沾满textView,随textView大小改变
|