1. android-percent-support-lib-sample介绍:

谷歌最新的百分比布局库的示例项目。其实LinearLayout的layout_weight也能实现百分比效果,不过这个更直接。

android-percent-support-lib-sample项目地址:

https://github.com/JulienGenoud/android-percent-support-lib-sample

简单效果:

 

 

复杂效果:

 

2. 百分比库使用Demo:

这里的Eclipse版本库代码(包含示例代码),我已经完整提交到Github。地址如下:

https://github.com/PocketBoy/Local/tree/master/Eclipse_android_percent_support

(1)点击上面的链接,下载库代码,解压,导入Eclipse之中:

(2)这里我们新建一个Android工程,命名位"PercentDemo",如下:

上面库文件需要引用android-support-v4.jar

(3)来到上面自定义属性文件attrs.xml,如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="PercentLayout_Layout">
<attr name="layout_widthPercent" format="string"/>
<attr name="layout_heightPercent" format="string"/>
<attr name="layout_marginPercent" format="string"/>
<attr name="layout_marginLeftPercent" format="string"/>
<attr name="layout_marginTopPercent" format="string"/>
<attr name="layout_marginRightPercent" format="string"/>
<attr name="layout_marginBottomPercent" format="string"/>
<attr name="layout_marginStartPercent" format="string"/>
<attr name="layout_marginEndPercent" format="string"/>
<attr name="layout_textSizePercent" format="string"/>
<attr name="layout_maxWidthPercent" format="string"/>
<attr name="layout_maxHeightPercent" format="string"/>
<attr name="layout_minWidthPercent" format="string"/>
<attr name="layout_minHeightPercent" format="string"/>
</declare-styleable>
</resources>

 至于怎么使用自定义属性,请参照笔记:

自定义控件(视图)28期笔记06:自定义控件之 自定义属性

(4)来到activity_main.xml布局文件之中:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentLinearLayout 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:orientation="vertical" > <android.support.percent.PercentLinearLayout
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="0dp"
app:layout_heightPercent="33.3%"
android:orientation="horizontal" > <View android:id="@+id/view_11"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="50%"
android:background="#ff44aacc" /> <View
android:id="@+id/view_12"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="50%"
android:background="#664466cc" />
</android.support.percent.PercentLinearLayout> <android.support.percent.PercentLinearLayout
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="0dp"
app:layout_heightPercent="33.3%"
android:orientation="horizontal" > <View android:id="@+id/view_21"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="25%"
android:background="#ff44ffcc" /> <View
android:id="@+id/view_22"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="25%"
android:background="#8585855c" /> <View android:id="@+id/view_23"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="25%"
android:background="#ff444545" /> <View
android:id="@+id/view_24"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="25%"
android:background="#556ff776" />
</android.support.percent.PercentLinearLayout> <android.support.percent.PercentLinearLayout
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="0dp"
app:layout_heightPercent="33.3%"
android:orientation="horizontal" > <View android:id="@+id/view_31"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="50%"
android:background="#ffffff00" /> <View
android:id="@+id/view_32"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_widthPercent="50%"
android:background="#ffff00ff" />
</android.support.percent.PercentLinearLayout> </android.support.percent.PercentLinearLayout>

布局效果如下:

(5)来到activity_main1.xml,如下:

<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"
android:background="@android:color/white" > <View
android:id="@+id/top_left"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
app:layout_heightPercent="20%"
app:layout_widthPercent="70%"
android:background="#ff44aacc" /> <View
android:id="@+id/top_right"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/top_left"
app:layout_heightPercent="20%"
app:layout_widthPercent="30%"
android:background="#ffe40000" /> <android.support.percent.PercentFrameLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/top_left"
android:layout_gravity="center"
app:layout_heightPercent="80%"
android:background="#ff00ff22" > <android.support.percent.PercentLinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
app:layout_heightPercent="100%"
app:layout_marginTopPercent="10%"
android:background="@android:color/white"
android:orientation="vertical"
>
<View
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="30%"
app:layout_widthPercent="10%"
android:background="#ff44ccdd" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="30%"
app:layout_widthPercent="90%"
android:background="#ffe400dd" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="20%"
app:layout_widthPercent="90%"
android:background="#ccc"
android:text="margin 15% of w"
app:layout_marginPercent="5%h"
/>
</android.support.percent.PercentLinearLayout>
</android.support.percent.PercentFrameLayout> </android.support.percent.PercentRelativeLayout>

布局效果如下:

(6)activity_main2.xml,如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.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:orientation="vertical"> <android.support.percent.PercentFrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:background="#ff44aacc"
app:layout_heightPercent="50%w"
app:layout_widthPercent="50%w"> <android.support.percent.PercentFrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:background="#ffcc5ec7"
app:layout_heightPercent="50%w"
app:layout_widthPercent="50%w"> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#ff7ecc16"
android:gravity="center"
android:text="margin 15% of w"
app:layout_marginPercent="15%w"
/> </android.support.percent.PercentFrameLayout> </android.support.percent.PercentFrameLayout> <TextView android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="bottom|right"
android:background="#44ff0000"
android:gravity="center"
android:text="15%w,15%w"
app:layout_heightPercent="15%w"
app:layout_marginPercent="5%w"
app:layout_widthPercent="15%w"/> </android.support.percent.PercentFrameLayout>

布局效果如下:

7. Android框架和工具之 android-percent-support-lib-sample(百分比支持)的更多相关文章

  1. 13. Android框架和工具之 Android Drawable Factory

    1. AndroidDrawableFactory 一个生成Android应用所需尺寸图片的工具. 托管在Github之中: https://github.com/tizionario/Android ...

  2. 3. Android框架和工具之 xUtils(DbUtils )

    1. xUtils简介 xUtils 包含了很多实用的android工具.xUtils 最初源于Afinal框架,进行了大量重构,使得xUtils支持大文件上传,更全面的http请求协议支持(10种谓 ...

  3. 3. Android框架和工具之 xUtils(BitmapUtils)

    1. BitmapUtils 作用: 加载bitmap的时候无需考虑bitmap加载过程中出现的oom和android容器快速滑动时候出现的图片错位等现象: 支持加载网络图片和本地图片: 内存管理使用 ...

  4. 3. Android框架和工具之 xUtils(HttpUtils)

    1. HttpUtils 作用: 支持同步,异步方式的请求: 支持大文件上传,上传大文件不会oom: 支持GET,POST,PUT,MOVE,COPY,DELETE,HEAD请求: 下载支持301/3 ...

  5. 10. Android框架和工具之 AppMsg(消息提示)

    1. AppMsg 优雅的弹出类似Toast的消息提示,支持3种状态Alert(警告),Confirm(确认)以及Info(消息).        2. AppMsg使用: (1)AppMsg下载地址 ...

  6. 5. Android框架和工具之 ZXing(二维码)

    Android进阶笔记06:Android 实现扫描二维码实现网页登录

  7. 3. Android框架和工具之 xUtils(ViewUtils )

    1. ViewUtils 作用: 完全注解方式就可以进行UI绑定和事件绑定. 无需findViewById和setClickListener等. 2. UI绑定 和 事件绑定 (1)UI绑定 下面我們 ...

  8. Android框架式编程之Android Architecture Components

    1. 当前Android开发面临的问题 Android开发不同于传统的桌面程序开发,桌面程序一般都有唯一的快捷方式入口,并且常作为单进程存在:而一个典型的Android应用通常由多个应用组件构成,包括 ...

  9. 6. Android框架和工具之 JSON解析

    Android进阶笔记17:3种JSON解析工具(org.json.fastjson.gson)

随机推荐

  1. OpenXML操作word

    OpenXML概述 项目中经常需要操作word,之前的方式是采用COM接口,这个接口很不稳定,经常报错.现在开始采用OpenXML.OpenXML(OOXML)是微软在Office 2007中提出的一 ...

  2. POJ1463 Strategic game (最小点覆盖 or 树dp)

    题目链接:http://poj.org/problem?id=1463 给你一棵树形图,问最少多少个点覆盖所有的边. 可以用树形dp做,任选一点,自底向上回溯更新. dp[i][0] 表示不选i点 覆 ...

  3. (图解版)SQL Server数据库备份与还原

        本文介绍了SQL Server数据库备份的两种方式.一种是直接拷贝数据库中的文件mdf 和日志文件ldf,另一种是生成脚本语言. 第一种方式:     选中需要备份的数据库,将数据库从运行的数 ...

  4. Computational Geometry Template_Polygon

    #include <stdlib.h> #include <math.h> #include <iostream> #define MAXN 1000 #defin ...

  5. 特现C语言编程特点的小代码,itoa,数值转换成字符串

    #define BASE_MAX (26 + 10) char const* itostr(int x, int base) { /* map 居中, 支技负余数 */ static char con ...

  6. android开发中提示:requires permission android.permission write_settings解决方法

    一.在Manifest.xml 中添加: <uses-permission android:name="android.permission.WRITE_CONTACTS" ...

  7. 通过css代码使边框变圆角(ie9以下浏览器不支持)

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-02-11) CSS代码: <style> #myDiv { border-radius: 4px; /*这句就是 ...

  8. (1) css的核心基础

     css的核心基础 1.css的基本语法在具体使用css之前,请各位兄弟姐妹先思考一个生活中的问题,一般情况下我们是如何描述一个人的呢? 小明{ 民族:汉族: 性格:温柔: 性别:男: 体重:68kg ...

  9. PageValidate 类

    转载:http://www.cnblogs.com/sufei/archive/2010/01/14/1648028.html using System.Text.RegularExpressions ...

  10. Hex-Rays Decompiler Tips and tricks Volatile memory

    https://www.hex-rays.com/products/decompiler/manual/tricks.shtml First of all, read the troubleshoot ...