首先,需要添加com.android.support:percent:24.1.1 包,版本随意。

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:percent:24.1.1'
}

}

  这个包给我们提供了PercentRelativeLayout以及PercentFrameLayout两种布局,

  支持的属性有layout_widthPercentlayout_heightPercent、 
  layout_marginPercentlayout_marginLeftPercent、 
  layout_marginTopPercentlayout_marginRightPercent、 
  layout_marginBottomPercentlayout_marginStartPercentlayout_marginEndPercent

     大概的内容就有这些,下面贴上一段代码及效果图

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.administrator.mingyishijia.LoginActivity">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
app:navigationIcon="@mipmap/left_back_gray_icon" android:id="@+id/activity_main_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"></android.support.v7.widget.Toolbar> <EditText
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="8%"
app:layout_widthPercent="70%"
android:background="@drawable/usereditor_background"
android:id="@+id/userName"
android:gravity="center"
android:layout_below="@+id/activity_main_toolbar"
app:layout_marginTopPercent="10%"
android:layout_centerHorizontal="true"
android:hint="请输入账号"/>
<EditText
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="8%"
app:layout_widthPercent="70%"
android:background="@drawable/usereditor_background"
android:id="@+id/password"
android:layout_below="@+id/userName"
android:gravity="center"
app:layout_marginTopPercent="2%"
android:layout_centerHorizontal="true"
android:hint="请输入密码"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="8%"
app:layout_widthPercent="70%"
android:background="@drawable/login_button_background"
android:id="@+id/login"
android:layout_below="@+id/password"
android:text="登 录"
android:textSize="18sp"
android:textColor="#ffffff"
android:layout_centerHorizontal="true"
app:layout_marginTopPercent="5%" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/forgetPassword"
android:layout_below="@+id/login"
android:layout_alignLeft="@+id/login"
app:layout_marginTopPercent="2%"
android:text="忘记密码"
android:textSize="12sp"
android:textColor="#1a81ff"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="90%"
android:id="@+id/l1"
android:orientation="horizontal"
android:clickable="false"
android:layout_centerHorizontal="true"
android:layout_below="@+id/forgetPassword"
app:layout_marginTopPercent="5%">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000"
android:layout_weight="1.1"
android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="或使用以下方式登录"
android:textSize="12sp"
android:gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000"
android:layout_weight="1.1"
android:layout_gravity="center"/>
</LinearLayout> <LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="15%"
app:layout_widthPercent="75%"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:layout_below="@+id/l1"
app:layout_marginTopPercent="5%"
android:id="@+id/linearLayout">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="60%"
app:layout_widthPercent="100%"
android:scaleType="fitCenter"
android:id="@+id/iv1"
android:src="@mipmap/weixin"/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
android:layout_below="@+id/iv1"
android:text="微信"
android:gravity="center"/>
</android.support.percent.PercentRelativeLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="60%"
app:layout_widthPercent="100%"
android:scaleType="fitCenter"
android:id="@+id/iv2"
android:src="@mipmap/aqq1"/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
android:layout_below="@+id/iv2"
android:text="QQ"
android:gravity="center"/>
</android.support.percent.PercentRelativeLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="60%"
app:layout_widthPercent="100%"
android:scaleType="fitCenter"
android:id="@+id/iv3"
android:src="@mipmap/dingding"
/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
android:layout_below="@+id/iv3"
android:text="钉钉"
android:gravity="center"/>
</android.support.percent.PercentRelativeLayout> </LinearLayout> </android.support.percent.PercentRelativeLayout>

        

Android适配--百分比的适配的更多相关文章

  1. Android屏幕相关概念和适配方法

    参考文档: 1.http://blog.csdn.net/carson_ho/article/details/51234308(略有修改) 2.http://www.cnblogs.com/cheng ...

  2. Android - 多语言自动适配

    Android为多语言适配提供了很大的方便.开发者不需要在代码中进行修改.只需要配置xml文件. res --> values 其中存放有xml文件.一般这些都是英文的字符串.我们可以存放其他语 ...

  3. Android P的APP适配总结,让你快人一步

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由QQ音乐技术团队发表于云+社区专栏 上篇:Android P 行为变更适配 Android P 这次有很多行为变更,其中不乏一些需要亟 ...

  4. Android通知栏介绍与适配总结(上篇)

    此文已由作者黎星授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知 ...

  5. Android Camera多屏幕适配解决预览照片拉伸

    通常,拍照预览页面的照片拉伸主要与下面两个因素有关: 1.     Surfaceview的大小 2.     Camera中的Preview的大小 如下图:     图中preview显示的是手机支 ...

  6. Android通知栏介绍与适配总结

    由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知栏玩法,谷歌也不得不对其进行更新迭代调整,增加新功能的同时,也在不断地改变样式,试图迎合更 ...

  7. 美团Android自动化之旅—适配渠道包

    http://tech.meituan.com/mt-apk-adaptation.html 概述 前一篇文章(美团Android自动化之旅-生成渠道包)介绍了Android中几种生成渠道包的方式,基 ...

  8. Android 屏幕适配之dimens适配

    Android 屏幕适配之dimens适配     转  https://blog.csdn.net/github_2011/article/details/72636851 在过去多个项目中一直使用 ...

  9. Android APP 多端适配

    Android APP 多端适配 传统的多终端适配方案,是为大尺寸 Pad开发一个特定的 HD版本. 但是目前支持 Android 系统的设备类型越来越丰富,不同类型的设备尺寸也越来越多样化,特定的H ...

随机推荐

  1. [性能测试]:关于消费类ISO8583协议脚本的开发

    一,要发送的报文,转化成16进制的,报文如下 "\x01\x52"//报文长度338 "\x60\x00\x24\x00\x00"//TPDU "\x ...

  2. 【Three.js】如何选中外部模型

    1.问题 three.js中模型选中使用的是射线法,根据摄像机角度,鼠标点击位置和模型选中的distance参数判断来选中模型.对于原生的矢量模型完全没有问题,但是当遇到导入的外部模型,如obj.st ...

  3. Mac 10.12安装Atom文本增强编辑工具

    下载: https://atom.io/

  4. 什么是WCF(转)

    什么是WCF(Windows Communication Foundation(WCF)) 大家可以百度一下了解什么是WCF.当然有些人看到密密麻麻的黑框白字就懒的读.即使读了 可能也没明白确切的含义 ...

  5. (转)nginx+iis实现负载均衡

    最近在研究分布式系统架构方面的知识,包括负载均衡,数据库读写分离,分布式缓存redis等.本篇先从负载均衡服务架构入手,关于负载均衡百度百科的定义如下:负载均衡,英文名称为Load Balance,其 ...

  6. (转)总结之:CentOS 6.5 MySQL数据库的基础以及深入详解

    总结之:CentOS 6.5 MySQL数据库的基础以及深入详解 原文:http://tanxw.blog.51cto.com/4309543/1395539 前言 早期MySQL AB公司在2009 ...

  7. 【文档】七、Mysql Binlog不同事件类型的事件内容

    下面主要讲述了每个类型的事件中的固定和可变部分的数据. Start_log_event_v3/START_EVENT_V3 这个事件出现在v1或v3的binlog文件的开头部分.对于4.0和4.1版本 ...

  8. java.lang.IllegalStateException: Unknown Priority XXXX 的解决方法

    异常信息: java.lang.IllegalStateException: Unknown Priority SYS_ERR_SMS at org.apache.log4j.Category.pri ...

  9. 标准差(bias) 方差(variance)

    偏差(bias) 偏差度量了学习算法的期望预测与真实结果的偏离程序, 即 刻画了学习算法本身的拟合能力 . 方差(variance) 方差度量了同样大小的训练集的变动所导致的学习性能的变化, 即 刻画 ...

  10. java突破------一撸到底(做Java开发,遇到瓶颈是保持现状还是寻求突破?)

    java突破------一撸到底(做Java开发,遇到瓶颈是保持现状还是寻求突破?) 很多人做Java开发2.3年之后,都会觉得自己遇到了瓶颈.什么都会又什么都不会,如何改变困境,为什么很多人写了7. ...