Android的布局支持百分比的设置进行开发,来学习如何去实现它,不过看起来会像网页的设置,比如宽度的设置属性是`layout_widthPercent`。在此之前,我们一般都会设置Linearlayout的weight权重来实现布局间的比例大小。

Percent support Library提供了两个新的类:

1.PercentRelativeLayout

2.PercentFrameLayout

创建新项目

创建一个新的项目来测试,修改`build.gradle`,需要引入以下库

`applyplugin:'com.android.application'

android {

compileSdkVersion23

buildToolsVersion"23.0.0"

defaultConfig {

applicationId"com.android.chaowen.percentdemo1"

minSdkVersion7

targetSdkVersion22

versionCode1

versionName"1.0"

}

buildTypes {

release {

minifyEnabledfalse

proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

}

}

}

dependencies {

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

compile'com.android.support:support-annotations:23.0.0'

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

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

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

}

  创建布局

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

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:id="@+id/first"

android:background="@color/sa_green_dark"

app:layout_heightPercent="50%"

app:layout_marginLeftPercent="25%"

app:layout_marginTopPercent="25%"

app:layout_widthPercent="50%" />

android:layout_width="0dp"

android:layout_height="32dp"

android:layout_alignLeft="@id/first"

android:layout_alignStart="@id/first"

android:layout_alignRight="@id/first"

android:layout_alignEnd="@id/first"

android:layout_below="@id/first"

android:layout_marginTop="8dp"

android:background="@color/light_grey" />

比例大小是通过`heightPercent`和`widthPercent`属性来设置百分比大小值。完全属于`RelativeLayout`的扩展类,值得一提的是,

不再需要设置`layout_width`和`layout_height`,注意了,这是新的库使用方法,因为这两个属性会被自动加入了。

百度比也可以用于设置边距。唯一区别的只是采取了百分比值。

最后一点需要注意,在第二个view,并没有直接设置比例的大小,但是它的位置是相对于第一个view.

android support Percent支持库开发的更多相关文章

  1. As环境下添加android support library依赖库

    2015年的google大会上,google发布了新的Android Support Design库的新组件之一,以此来全面支持Material Design 设计风格的UI效果,为了可以使用这些新颖 ...

  2. Android百分比布局支持库介绍——com.android.support:percent(转)

    转载自http://www.apkbus.com/forum.php?mod=viewthread&tid=244752&extra=&_dsign=0b699c42 在此之前 ...

  3. Android添加百分比布局库时显示Failed to resolve: com.android.support.percent:问题

    这是看第一行代码中遇到的问题,要添加百分比布局库的依赖时要在app下的bulid.gradle添加以下代码 implementation fileTree(dir:'libs',include:['* ...

  4. (转)Android Support Percent百分比布局

    一.概述 周末游戏打得过猛,于是周天熬夜码代码,周一早上浑浑噩噩的发现 android-percent-support-lib-sample(https://github.com/JulienGeno ...

  5. Android Studio com.android.support:percent 导入错误 - 转

    看第一行代码(第二版的)书,讲了一个关于PercentFrameLayout和PercentRelativeLayout的部分,书上在build.gradle中导入了com.android.suppo ...

  6. Android support library支持包常用控件介绍(一)

    谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现Material Design设计效果,官方给出了Android support design library 支 ...

  7. Android support library支持包常用控件介绍(二)

    谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现 Material Design设计效果,官方给出了Android support design library ...

  8. Android百分比布局支持库(android-percent-support)

    Android中提供了五种布局,其中用的最多的就是:LinearLayout, RelativeLayout 和 FrameLayout这三种布局,在对某一界面进行布局时最先想到也是通过这三种来布局的 ...

  9. [原]ffmpeg编译android 硬解码支持库 libstagefright

    最近花了一天时间将ffmpeg/tools/build_stagefright执行成功,主要是交叉编译所需要的各种动态库的支持没链接上,导致各种报错,基本上网络上问到的问题我都碰到了,特此记录下来. ...

随机推荐

  1. OpenFiler安装与基本配置

    一.            安装篇 1.      插入安装盘 2.      选择键盘输出 3.      对硬盘进行分区 4.      删除所有数据并重新分区 5.      配置IP地址等信息 ...

  2. Ajax Array Json 示例

    function functionName(){ var list=new Array(); $("td.classA").each(function(){ list.push($ ...

  3. javascript之正则表达式总结

    了解RegExp类型: ECMAScript通过RegExp类型来支持正则表达式. var expression=/pattern/flags; 正则表达式的模式(pattern)部分: 可以是任何简 ...

  4. 《锋利的jQuery》心得笔记--Two Sections

    第三章 1.    DOM操作(节点) 1)         查找节点可以查找元素节点和属性节点 2)         创建节点: (1)       创建元素节点 var addLi = $(“&l ...

  5. 了解GDAL的图像处理/Python

    GDAL是一个操作各种栅格地理数据格式的库.包括读取.写入.转换.处理各种栅格数据格式(有些特定的格式对一些操作如写入等不支持).它使用了一个单一的抽象数据模型就支持了大多数的栅格数据(GIS对栅格, ...

  6. FPGA使用技巧

    1 IOB       为了保证FPGA输入输出接口的时序,一般会要求将输入管脚首先打一拍再使用,输出接口也要打一拍再输出FPGA.将信号打一拍的方法是将信号通过一次寄存器,而且必须在IOB里面的寄存 ...

  7. vim 安装与运行以及代码的运行

    vi功能是最弱的,也是*nix操蛋之后最基本的editor.后来vi被增强加入众多特性,这就是vim.再后来vim加入图形接口,gvim诞生了.功能最强的是gvim,它的很多特性vim并不支持,vi更 ...

  8. Configuration python CGI in XAMPP in win-7

    1.After install XAMPP,we need add the path of the Mysql just find the path and add it to your sys-pa ...

  9. IIFE-js中(function(){…})()立即执行函数写法理解

    介绍IIFE IIFE的性能 使用IIFE的好处 IIFE最佳实践 jQuery优化 在Bootstrap源码(具体请看<Bootstrap源码解析>)和其他jQuery插件经常看到如下的 ...

  10. js文本框验证

    1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafte ...