版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010046908/article/details/48802909

标题:Android百分比布局初探

依赖库:——com.android.support:percent

实现原理:

在这个包里面有两个新的容器类
1、PercentRelativeLayout
2、PercentFrameLayout
在此看来,这两个类很显然是继承自 FrameLayout和 RelativeLayout两个容器类。

新的容器有了一些设置百分比的属性,下面我们来了解一下:
  • layout_widthPercent
设置控件宽度为父容器的宽的百分比
  • layout_heightPercent
设置控件高度为父容器的高的百分比
  • layout_marginPercent
  • layout_marginLeftPercent
设置控件与左边控件的距离为父容器的宽度的百分比
  • layout_marginTopPercent
设置控件与上方控件的距离为父容器的高度的百分比
  • layout_marginRightPercent
设置控件与右边控件的距离为父容器的宽度的百分比
  • layout_marginBottomPercent
设置控件与下方控件的距离为父容器的高度的百分比
  • layout_marginStartPercent
与上面的说明类似
  • layout_marginEndPercent
与上面的说明类似
从命名的方式我们可以知道,原来用某些具体单位(如dp)的设置现在都可以用百分比的方式进行设置了,例如设置控件的宽度layout_width原来我们是这样玩的android:layout_width="match_parent"现在用了百分比的属性之后呢,可以这样玩了app:layout_widthPercent="50%",这里的百分比是相对于父容器而言的。

官方文档地址:https://juliengenoud.github.io/android-percent-support-lib-sample/
官网代码:
1.

PercentFrameLayout
<android.support.percent.PercentFrameLayoutxmlns: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"/><ImageViewapp:layout_widthPercent="50%"app:layout_heightPercent="50%"app:layout_marginTopPercent="25%"app:layout_marginLeftPercent="25%"/></android.support.percent.PercentFrameLayout/>

2.PercentRelativeLayout

<android.support.percent.PercentRelativeLayoutxmlns: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"><Viewandroid:id="@+id/top_left"android:layout_width="0dp"android:layout_height="0dp"android:layout_alignParentTop="true"android:background="#ff0000"app:layout_heightPercent="30%"app:layout_widthPercent="70%" /><Viewandroid:id="@+id/top_right"android:layout_width="0dp"android:layout_height="0dp"android:layout_alignParentTop="true"android:layout_toRightOf="@+id/top_left"android:background="#00ff00"app:layout_heightPercent="30%"app:layout_widthPercent="30%" /><Viewandroid:id="@+id/centre"android:layout_width="match_parent"android:layout_height="0dp"android:layout_below="@+id/top_left"android:background="#0000ff"app:layout_marginLeftPercent="10%"app:layout_marginRightPercent="20%"app:layout_marginTopPercent="10%"app:layout_marginBottomPercent="10%"app:layout_heightPercent="40%" /><Viewandroid:layout_width="match_parent"android:layout_height="0dp"android:id="@+id/bottom"android:layout_below="@+id/centre"android:background="#00f0ff"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"app:layout_heightPercent="10%"/></android.support.percent.PercentRelativeLayout>

效果:

Android百分比布局初探相关推荐

  1. android如何看百分比版本,【JAVA】Android百分比布局

    开发我人生第一个app的时候,我在想有没有这么一种布局能适应任何手机的分辨率,今天让我们一起来看看Android 百分比布局PercentRelativeLayout. 使用这种布局首先我们要在gra ...

  2. Android百分比布局支持和垂直TextView

    In this tutorial, we'll discuss and implement Android Percent Layout Support Library. Furthermore, w ...

  3. android 边距 百分比,Android百分比布局:PercentRelativeLayout

     Android百分比布局:PercentRelativeLayout 在最新的Android support包中,增加了开发者期待的百分比布局PercentRelativeLayout和Perc ...

  4. Android 百分比布局

    Android 百分比布局库(percent-support-lib) 解析与扩展 扩展库github地址

  5. Android 百分比布局(支持AndroidX)

    Android 百分比布局 添加依赖 代码使用 添加依赖 implementation 'com.android.support:percent:25.2.0' 我的项目是AndroidX的,依然用这 ...

  6. android百分比布局失效,Android 百分比布局库【原创】

    为了解决android手机适配问题,我们经常想如果可以按照百分比的方式进行界面布局,这样适配各种屏幕就简单多了吧!现在谷歌正式提供百分比布局支持库(android-support-percent-li ...

  7. Android 百分比布局、权重、隐藏TitleBar、引入自定义控件

    一.LinearLayout权重 1.1.android:layout_weight="1" 两个控件设置为1可以将屏幕等分为两份,更改数值可以根据各自数值各占有屏幕的尺寸    ...

  8. Android 百分比布局+ScrollView

    主要分为PercentRelativeLayout,和 PercentFrameLayout PercentRelativeLayout 一.添加依赖 compile 'com.android.sup ...

  9. android百分比布局适配,安卓屏幕适配-百分比布局

    屏幕适配-百分比布局 原理:以父容器尺寸作为参考,在View的加载过程,根据当前父容器实际尺寸换算出目标尺寸,在作用在View上. 百分比布局实际是对容器的一中扩展,扩展的是宽高等比例的设置. 1.自 ...

最新文章

  1. 简单的 HTTP 调用,为什么时延这么大?
  2. win7光盘修复计算机在哪,win7如何创建系统还原及系统修复光盘功能应用
  3. linux top交叉编译_ARM Linux交叉编译工具链的制作
  4. 在C++中可以用3种方法访问一个字符串
  5. excel实战应用案例100讲(十二)-用Excel做一个自动抽奖器
  6. 漫步数学分析九——级数
  7. mysql启动失败2005_数据库2005服务启动不了
  8. HTML示例06---水平线
  9. cesium模型不遮挡点线面_VueCLI3.0干货系列之集成Cesium三维地球框架
  10. 计算机单片机实训报告,单片机实训报告范文
  11. Django连接MySQL8.0报错django.db.utils.OperationalError: (1045, “Access denied for user ‘16066‘@‘localhos
  12. 图10——判断顶点u和顶点v是否存在简单路径
  13. adjacency list(邻接表)神物
  14. 完全平方数(C语言,调用函数)
  15. 岁月温柔-2 又住院了,祈祷早日康复
  16. 用UNetbootin 制作Linux 安装U盘
  17. 计算机老师的寄 语,计算机专业老师毕业赠言
  18. 解析!如何从手机网站直接跳转到微信添加好友界面
  19. 3388=24及24点游戏的穷举算法
  20. 解决Win10下Fliqlo无法显示,显示一个Fi的图标

热门文章

  1. php 编译错误,PHP 编译错误及解决办法
  2. 自定义request_Spring Security 自定义登录认证(二)
  3. 将数据导入到mysql_06955.10.2如何将CM的外部PostgreSQL数据库迁移至MySQL服务
  4. 不需要网络的调频收音机_测试工程师真的不需要懂网络知识么?
  5. php 信号量 关闭,PHP信号量基本用法实例详解
  6. linux怎么进入bios查看mac地址,详细教您查看本机mac地址
  7. 机器学习之--梯度下降和最小二乘法算线性回归
  8. BZOJ4589: Hard Nim(FWT 快速幂)
  9. 递归方法:对于树形结构的表,根据当前数据获取无限极的父级名称
  10. jQuery-处理class属性