美文网首页Android相关
安卓百分比布局

安卓百分比布局

作者: Condor_c33a | 来源:发表于2017-09-12 11:05 被阅读75次

1. Recycle机制

原理便是维护一个对象池,将不再使用但是可能再次使用的对象引用保留在这个对象池里,下次需要的时候来到这个对象池获取。

Android经常使用这个机制,例如Message类,特地注意一下,由于这个机制, 使用Message时,不能调用其recycle()方法,这会导致Message内部的链表(该链表用来存储Message对象)变成循环链表,Message的Recycle机制将会失效。

详细可见 TiouLims 的文章

2. 使用android support Percent支持库

现在有两种布局支持百分比PercentRelativeLayout,PercentFrameLayout

需要在支持库中加入compile 'com.android.support:percent:23.0.0'

如下

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:23.0.1'

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

}

在使用到

android.support.percent.PercentRelativeLayout

android.support.percent.PercentFrameLayout

的布局文件头中需要加入

xmlns:app="http://schemas.android.com/apk/res-auto"

支持的属性有

控件宽度:app:layout_widthPercent="x%"

控件高度:app:layout_heightPercent="x%"

控件距离父布局左边的距离:app:layout_marginLeftPercent="x%"

控件距离父布局右边的距离:app:layout_marginRightPercent="x%"

控件距离父布局上边的距离:app:layout_marginTopPercent="x%"

控件距离父布局下边的距离:app:layout_marginBottomPercent="x%"

控件距离父布局开始边的距离:app:layout_marginStartPercent="x%"

控件距离父布局结束边的距离:app:layout_marginEndPercent="x%"

实例

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:id="@+id/id_btn"

app:layout_widthPercent="25%"

app:layout_heightPercent="50%"

app:layout_marginLeftPercent="10%"

app:layout_marginTopPercent="5%"

android:text="i am a button"/>

相关文章

  • 布局

    今天学习了安卓的四种布局方式 线性布局 相对布局 帧布局 百分比布局

  • 安卓百分比布局

    1. Recycle机制 原理便是维护一个对象池,将不再使用但是可能再次使用的对象引用保留在这个对象池里,下次需要...

  • 基础篇

    学习了安卓布局:LinearLayout(线性布局) RelativeLayout(相对布局)

  • 安卓开发入门教程-常用布局_布局引用

    关注 安卓007 ,免费获取全套安卓开发学习资料 什么是布局引用 布局引用不是一种新的布局哦,目的是复用某些布局文...

  • 前端布局种类

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

  • 安卓布局

    RelativeLayout 第一类:属性值为true可false android:layout_centerHr...

  • 安卓布局,

    前言 在进行Android开发中,常常需要用到各种布局来进行UI的绘制,今天我们就来讲下Android开发中最常用...

  • 安卓布局

    RelativeLayout 第一类:属性值为true可false android:layout_centerHr...

  • 安卓布局

    Android 中常用的布局 FrameLayout RelativeLayout LinearLayout Ab...

  • 安卓布局

    layout_margin和padding margin属性是控制控件与控件之间的间隙,属于对控件外部的控制。pa...

网友评论

    本文标题:安卓百分比布局

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