Android:屏幕适配,解决屏幕大尺度适配(1)

本人用Android Studio

优势:

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代码下载地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值