IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> 百分比布局 -> 正文阅读

[移动开发]百分比布局

一、使用
导库:
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大小改变

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-08-03 11:19:29  更:2021-08-03 11:21:25 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/5 19:24:59-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码