Android AutoLayout万能的适配布局

 产品给出需求文档和草图,设计就会按照产品的需求设计一些界面,

010735_AV9Q_1398907.jpg

 

这样设计图开发中很常见,这些设计都会去标注好,一般开发者都是用像素转换成dp/dip/sp 我们这样的时候很多。

  <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:orientation="vertical"
            android:paddingBottom="5dip" >

            <ImageView
                android:id="@+id/iv_bottom_line"
                android:layout_width="40dip"
                android:layout_height="2dip"
                android:layout_marginLeft="20dip"
                android:scaleType="matrix"
                android:src="@color/red" />
        </LinearLayout>

但是对新的AutoLayout就不同了,

 

  <AutoLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:orientation="vertical"
            android:paddingBottom="10px" >

            <ImageView
                android:id="@+id/iv_bottom_line"
                android:layout_width="80px"
                android:layout_height="4px"
                android:layout_marginLeft="40px"
                android:scaleType="matrix"
                android:src="@color/red" />
        </AutoLayout>

直接按照设计稿中标的那种像素填写就可以,看到这,我相信最大的疑问就是:px 能用px完成适配吗,其实根据px像素在内部会进行百分比转换,720px高度的屏幕,只要填写在720px

目前支持属性

  • layout_width
  • layout_height
  • layout_margin(left,top,right,bottom)
  • pading(left,top,right,bottom)
  • textSize

 

  dependencies {
    compile project(':autolayout')
}
 

 

 

关注公众号:

                     

转载于:https://my.oschina.net/qxf323/blog/551627

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值