Git Product home page Git Product logo

androidmultiscreenlayout's Introduction

Android 多屏幕适配

Build Status Software License Bintray

使用方法:

compile 'com.zzzmode.android:layoutcompat:1.0'

或者download jar

首先布局尺寸单位必须是px,也就是设计师给标注的是多少就在布局里写多少,然后在onCreat()setContentView()之后调用以下方法即可适配多种屏幕。

LayoutSizeCompat.init(this);   
new LayoutSizeCompat.DesignSizeBuilder(1080,1920).builder().adjustSize(this);

其中init()方法可以只需要调用一次,(1080,1920)是根据UI的设计图尺寸得到的,简单用法,可以查看simple.

注意事项:

  • 必要要在setContentView() 之类的方法后面调用,否则不起作用的
  • 布局单位要用px,如果是xml布局要是px单位,java代码布局默认就是px单位的
  • 如果是ListView之类的可回收子view的需要在LayoutInflater.inflate() 创建view之后调用adjustSize() 方法进行适配
  • 不要多次调用adjustSize() 方法,否则会导致布局显示不正常,一般在onCreat() 之后调用一次即可
  • TextView 可以使用android:includeFontPadding="false" 或者 setIncludeFontPadding(false) 取消文字的一点上下边距
  • 调用adjustSize() 会遍历整个ViewTree,所有建议尽量不要嵌套过多的view,如果可以,最好使用代码生成布局而不是使用xml,使用java代码创建的布局要比xml快
  • 因为Google推荐使用dp作为布局单位,但是用px也并不影响界面显示

androidmultiscreenlayout's People

Contributors

8enet avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.