Android适配--百分比的适配
首先,需要添加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_widthPercent、layout_heightPercent、 layout_marginPercent、layout_marginLeftPercent、
layout_marginTopPercent、layout_marginRightPercent、 layout_marginBottomPercent、layout_marginStartPercent、layout_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适配--百分比的适配的更多相关文章
- Android屏幕相关概念和适配方法
参考文档: 1.http://blog.csdn.net/carson_ho/article/details/51234308(略有修改) 2.http://www.cnblogs.com/cheng ...
- Android - 多语言自动适配
Android为多语言适配提供了很大的方便.开发者不需要在代码中进行修改.只需要配置xml文件. res --> values 其中存放有xml文件.一般这些都是英文的字符串.我们可以存放其他语 ...
- Android P的APP适配总结,让你快人一步
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由QQ音乐技术团队发表于云+社区专栏 上篇:Android P 行为变更适配 Android P 这次有很多行为变更,其中不乏一些需要亟 ...
- Android通知栏介绍与适配总结(上篇)
此文已由作者黎星授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知 ...
- Android Camera多屏幕适配解决预览照片拉伸
通常,拍照预览页面的照片拉伸主要与下面两个因素有关: 1. Surfaceview的大小 2. Camera中的Preview的大小 如下图: 图中preview显示的是手机支 ...
- Android通知栏介绍与适配总结
由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知栏玩法,谷歌也不得不对其进行更新迭代调整,增加新功能的同时,也在不断地改变样式,试图迎合更 ...
- 美团Android自动化之旅—适配渠道包
http://tech.meituan.com/mt-apk-adaptation.html 概述 前一篇文章(美团Android自动化之旅-生成渠道包)介绍了Android中几种生成渠道包的方式,基 ...
- Android 屏幕适配之dimens适配
Android 屏幕适配之dimens适配 转 https://blog.csdn.net/github_2011/article/details/72636851 在过去多个项目中一直使用 ...
- Android APP 多端适配
Android APP 多端适配 传统的多终端适配方案,是为大尺寸 Pad开发一个特定的 HD版本. 但是目前支持 Android 系统的设备类型越来越丰富,不同类型的设备尺寸也越来越多样化,特定的H ...
随机推荐
- Redis报错:redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snap
首先找到出现错误的原因: redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but ...
- 最小生成树--牛客练习赛43-C
牛客练习赛43-C 链接: https://ac.nowcoder.com/acm/contest/548/C 来源:牛客网 题目描述 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 ...
- (转)InnoDB存储引擎MVCC实现原理
InnoDB存储引擎MVCC实现原理 原文:https://liuzhengyang.github.io/2017/04/18/innodb-mvcc/ 简单背景介绍 MySQL MySQL是现在最流 ...
- ACM练习网站
1.http://www.acmerblog.com/ Acm之家 2.http://acm.nyist.net/JudgeOnline/problemset.php 南阳理工学院
- TortoiseGit学习系列之Windows上TortoiseGit的安装详解(图文)
不多说,直接上干货! TortoiseGit的安装准备 首先你得安装windows下的msysgit. 安装版本控制器客户端TortoiseGit [不习惯英文的朋友,也可以下个语言包]. 下载地址: ...
- Go语言学习笔记三: 常量
Go语言学习笔记三: 常量 定义常量 常量就是在声明后不能再修改的量. const x int = 100 const y string = "abc" const z = &qu ...
- WPF 自定义NotifyPropertyChanged
该工具类实现INotifyPropertyChanged接口 /// <summary> /// 实现了属性更改通知的基类 /// </summary> public clas ...
- PHP之mb_convert_case使用
mb_convert_case (PHP 4 >= 4.3.0, PHP 5, PHP 7) mb_convert_case - Perform case folding on a string ...
- 2.2.2 加入factory机制
上一节给出了一个只有driver.使用UVM搭建的验证平台.严格来说这根本就不算是UVM验证平台,因为UVM的特性几乎一点都没有用到.像上节中my_driver的实例化及drv.main_phase的 ...
- c++删除容器中的奇数
出自 c++ primer(4th)282页,26题 题意 数组ia[]={0,1,1,2,3,5,8,13,21,55,89};把ia复制到一个list容器中.使用单个迭代器参数版本的erase() ...