Android AutoLayout万能的适配布局

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

Android AutoLayout万能的适配布局_第1张图片


这样设计图开发中很常见,这些设计都会去标注好,一般开发者都是用像素转换成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')
}

你可能感兴趣的:(Android AutoLayout万能的适配布局)