GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - guojunustb/AndroidAutoLayout: Android屏幕适配方案,直接填写设计图上的像素尺寸即可完成适配,最大限度解决适配问题。

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
app
app
 
 
autolayout
autolayout
 
 
gradle/wrapper
gradle/wrapper
 
 
sample
sample
 
 
.gitignore
.gitignore
 
 
AutoLayout.iml
AutoLayout.iml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
autolayout_01.png
autolayout_01.png
 
 
autolayout_02.png
autolayout_02.png
 
 
autolayout_03.png
autolayout_03.png
 
 
autolayout_04.png
autolayout_04.png
 
 
autolayout_08.png
autolayout_08.png
 
 
autolayout_09.png
autolayout_09.png
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

AndroidAutoLayout

Android屏幕适配方案,直接填写设计图上的像素尺寸即可完成适配。

非常感谢 : 吃土豆的人 的协作。

效果图

最大幅度解决适配问题,并且最大化方便开发者。

so,看下用法:

你没有看错,拿到设计稿,在布局文件里面直接填写对应的px即可,px:这里的px并非是Google不建议使用的px,在内部会进行转化处理。

看下不同分辨率下的效果:

768*1280,Andriod 4.4.4

480*800,Android 2.3.7

上述两个机器的分辨率差距相当大了,但是完美实现了适配,最为重要的是:

  • 再也不用拿着设计稿去想这控件的宽高到底取多少dp
  • 再也不用去为多个屏幕去写多个dimens
  • 再也不用去计算百分比了(如果使用百分比控件完成适配)
  • 再也不用去跟UI MM去解释什么是dp了

你所要做的就是抄抄设计稿上面的px,直接写入布局文件。

还有很多好处,比如上面的Item里面元素比较多,如果标识的比较全面,一个FrameLayout,里面的View填写各种marginLeft,marginTop就能完美实现,几乎不需要嵌套了。

用法

  • Android Studio

将autolayout引入

dependencies {
    compile project(':autolayout')
}

在你的项目的AndroidManifest中注明你的设计稿的尺寸。

<meta-data android:name="design_width" android:value="768"></meta-data>
<meta-data android:name="design_height" android:value="1280"></meta-data>
    

在你的Activity的onCreate里面写入: AutoLayout.getInstance().auto(this, true);

@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        AutoLayout.getInstance().auto(this, true);
    }

在布局文件中编写时,将:

  • LinearLayout -> AutoLinearLayout
  • RelativeLayout -> AutoRelativeLayout
  • FrameLayout -> AutoFrameLayout

目前支持属性

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

注意事项

  • TextView的高度问题

设计稿一般只会标识一个字体的大小,比如你设置textSize="20px",实际上TextView所占据的高度肯定大于20px,字的上下都会有一定的建议,所以一定要灵活去写字体的高度,比如对于text上下的margin可以选择尽可能小一点。或者选择别的约束条件去定位(比如上例,选择了marginBottom)

其他信息

作者信息:

  • hongyangAndroid
  • 吃土豆的人

灵感来自:

  • android-percent-support-lib-sample
  • android-percent-support-extend
  • Android 屏幕适配方案

About

Android屏幕适配方案,直接填写设计图上的像素尺寸即可完成适配,最大限度解决适配问题。

blog.csdn.net/lmj623565791/article/details/49990941

Resources

Readme
Apache-2.0 license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.