美文网首页
百分比布局(percentlayout)的使用

百分比布局(percentlayout)的使用

作者: 名字_都被占了 | 来源:发表于2018-05-16 00:05 被阅读0次

先添加如下依赖:

 compile 'com.android.support:percent:27.1.0'

主要属性如下,注意这些属性没有代码提示功能,要自己输入,我的android studio是这样的,手动输出:

layout_widthPercent
layout_heightPercent
layout_marginPercent
layout_marginLeftPercent
layout_marginTopPercent
layout_marginRightPercent
layout_marginBottomPercent
layout_marginStartPercent
layout_marginEndPercent
layout_aspectRatio

示例代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.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:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF4081"
        app:layout_heightPercent="100%"
        app:layout_marginPercent="4%"
        app:layout_widthPercent="10%"/>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/textView"
        android:background="#80FF4081"
        app:layout_heightPercent="80%"
        app:layout_marginPercent="4%"
        app:layout_widthPercent="10%"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/textView1"
        android:background="#60FF4081"
        app:layout_heightPercent="60%"
        app:layout_marginPercent="4%"
        app:layout_widthPercent="10%"/>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/textView2"
        android:background="#40FF4081"
        app:layout_heightPercent="40%"
        app:layout_marginPercent="4%"
        app:layout_widthPercent="10%"/>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/textView3"
        android:background="#20FF4081"
        app:layout_heightPercent="20%"
        app:layout_marginPercent="4%"
        app:layout_widthPercent="10%"/>
</android.support.percent.PercentRelativeLayout>

效果图:


相关文章

  • PercentLayout 百分比布局记录

    PercentLayout 百分比布局,控制子view 在布局文件占用的大小,多适配方案的一种比较好的选择。 拥有...

  • 百分比布局(percentlayout)的使用

    先添加如下依赖: 主要属性如下,注意这些属性没有代码提示功能,要自己输入,我的android studio是这样的...

  • Android百分比布局:PercentLayout

    天了噜,Android布局还能这么玩?两天没更新了,感觉整个人都不帅了。赶紧奉上神器压压惊,此处应该有支烟。今天的...

  • 前端布局种类

    1、流式布局(百分比布局) 2、flex布局(百分比布局) 3、rem布局(百分比布局)

  • flex布局总结

    --- flex 及 使用场景 App 的 百分比布局,使用flex弹性布局来排布 微信小程序的布局就使用f...

  • 使用PercentLayout布局实现固定比例控件

    欢迎Follow我的GitHub, 关注我的简书. 其余参考Android目录. PercentLayout是百分...

  • 响应式布局

    弹性布局 浮动+百分比布局 Flex布局 悬浮+百分比布局 浮动+百分比布局好处 网页内容宽度自适应 多设备都适用...

  • Android自定义百分比布局

    一、Google的百分比布局 关于百分比布局,其实Google为我们提供了一套方案,使用方式非常简单,跟我们之前使...

  • 流式布局

    流式布局(百分比布局) 流式布局就是百分比布局,也称为非固定像素布局 通过将盒子的宽度设置成百分比,从而根据屏幕的...

  • Android:百分比布局 布局嵌套 Log Toast

    添加依赖 implementation 'androidx.percentlayout:percentlayout...

网友评论

      本文标题:百分比布局(percentlayout)的使用

      本文链接:https://www.haomeiwen.com/subject/szjudftx.html