Android:屏幕适配,解决屏幕大尺度适配(1)
2015-11-23 16:16
579 查看
本人用Android Studio
优势:
使用方式:
设计稿效果:
设计稿代码:
需要引入的ku文件: ku代码下载地址
优势:
1.再也不用拿着设计稿去想这控件的宽高到底取多少dp 2.再也不用去为多个屏幕去写多个dimens 3.再也不用去计算百分比了(如果使用百分比控件完成适配) 4.再也不用去跟UI MM去解释什么是dp了
使用方式:
1.导入库 dependencies { compile project(':autolayout') } 2.在你的项目的AndroidManifest中注明你的设计稿的尺寸。 <meta-data android:name="design_width" android:value="768"></meta-data> <meta-data android:name="design_height" android:value="1280"></meta-data> 3.在你的Activity的onCreate里面写入: @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AutoLayout.getInstance().auto(this, true);//写入重点 }
设计稿效果:
(1)768*1280,Andriod 4.4.4
480*800,Android 2.3.7
设计稿代码:
<com.zhy.autolayout.AutoLinearLayout 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" android:background="#AAcccccc" android:orientation="vertical" tools:context=".MainActivity"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" > <com.zhy.autolayout.AutoLinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.zhy.autolayout.AutoLinearLayout android:layout_width="match_parent" android:layout_height="86px" android:layout_marginTop="26px" android:background="#ffffffff" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/id_tv_add" android:text="新增旅客" android:textColor="#1fb6c4" android:textSize="32px" app:layout_auto_textSizeBaseWidth="true" /> </com.zhy.autolayout.AutoLinearLayout> <com.zhy.autolayout.AutoRelativeLayout android:layout_width="match_parent" android:layout_height="108px" android:layout_marginTop="26px" android:background="#ffffffff" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="22px" android:layout_marginTop="16px" android:text="王大炮 WANG.DAPAO" android:textColor="#333" android:textSize="28px" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="16px" android:layout_marginLeft="22px" android:text="护照:G50786449" android:textColor="#999" android:textSize="26px" /> </com.zhy.autolayout.AutoRelativeLayout> <com.zhy.autolayout.AutoRelativeLayout android:layout_width="match_parent" android:layout_height="108px" android:layout_marginTop="26px" android:background="#ffffffff" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="22px" android:layout_marginTop="16px" android:text="王大炮 WANG.DAPAO" android:textColor="#333" android:textSize="28px" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="16px" android:layout_marginLeft="22px" android:text="护照:G50786449" android:textColor="#999" android:textSize="26px" /> </com.zhy.autolayout.AutoRelativeLayout> <com.zhy.autolayout.AutoRelativeLayout android:layout_width="match_parent" android:layout_height="108px" android:layout_marginTop="26px" android:background="#ffffffff" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="22px" android:layout_marginTop="16px" android:text="王大炮 WANG.DAPAO" android:textColor="#333" android:textSize="28px" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="16px" android:layout_marginLeft="22px" android:text="护照:G50786449" android:textColor="#999" android:textSize="26px" /> </com.zhy.autolayout.AutoRelativeLayout> </com.zhy.autolayout.AutoLinearLayout> </ScrollView>
需要引入的ku文件: ku代码下载地址
相关文章推荐
- Android:过滤掉输入法中的表情
- Android studio 打包、混淆
- 常见的android弹出对话框
- android activity学习
- Android下ffmpeg、SDL的编译
- Android double保留两位小数:截取 和 四舍五入
- Android编程记录ListView标记行状态的方法
- android javah 找不到类
- Android图片处理方法大全
- Android实现字母索引查找地名、联系人(一)
- android应用开发_通过手机QQ分享到空间出现分享错误的无奈原因
- android“设置”里的版本号
- android“设置”里的版本号
- 【1】14种Android Sensor
- 中科院开源协会镜像站 Android SDK镜像测试发布
- android 通过getDimension,getDimensionPixelOffset和getDimensionPixelSize获取dimens.xml文件里面的变量值
- Android开发进阶系列(三) 系统参数的获取和Broadcast
- Android 使用存放在存assets文件夹下的SQLite数据库
- Android Studio 快捷键
- Android libs中jar源码查看