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 ...
随机推荐
- 我也学习JAVA多线程-join
在工作中,挺少遇到join关键字,但很多多线程资料和面试过程中,初中级开发工程师总会遇到join. 今天一起学习下join. join的作用:等待指定的时间(当为0时,一直等待),直到这个线程执行结束 ...
- 认识CSS中标题引入icon图标
前端之HTML,CSS(十一) icon图标 icon图标的使用 获取网站的中标题icon图标,以京东为例:在域名后添加/favicon.ico Enter打开 鼠标右键,图标另存为下载icon图标, ...
- python3随机生成中文字符
运行环境在Python3.6下,Python2的解决方案网上有很多. ---2017.10.18 第一种方法:Unicode码 在unicode码中,汉字的范围是(0x4E00, 9FBF) impo ...
- 【数组】Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- 利用setTimeout来实现setInterval
在Js中,当我们要在一定间隔时间内不断执行同一函数,我们可以使用setInterval函数,但setInterval在某些情况下使用时也存在一定问题. 1.不去关心回调函数是否还在运行 在某些情况下, ...
- codeblocks 控制台一闪而过
不要点红的运行,那是调试,点绿色的三角形,那才是运行,不会一闪而过
- 关于语法节点Tree、类型Type和符号Symbol
每个语法节点Tree都有Type属性,部分的语法节点有Symbol属性,如下: 与Symbol类型与Type类型之间的关系如下: 下面是Symbol与Type之间的关系: (1)MethodSymbo ...
- scrapyd远程连接配置
安装scrapyd: pip install scrapyd 默认scrapyd启动是通过scrapyd就可以直接启动,bind绑定的ip地址是127.0.0.1端口是:6800,这里为了其他主机可以 ...
- Kibana插件sentinl实现邮件报警
为什么会突然想用到对日志的异常内容进行邮件报警,是因为在上周公司的线上业务多次出现锁表,开发在优化sql的同时,我也在想是不是可以对日志的异常内容进行检测并实现邮件预警. 在网上查询了一些资料后,决定 ...
- windows 7 做AP
启动脚本: @echo off netsh wlan set hostednetwork mode=allow ssid=<ap-name> key=<password> ne ...