Android app class responsive design]

Source: Internet
Author: User

This article is also published in the oschina blog Park... Introduction

I have been developing android for some time. I have been paying attention to android 1.6 since I was in college, and now android 4.2 has come out. I have witnessed the development of android. Today, after looking at the distribution chart of the android version, according to google's official display, android 4.0 and above already have 34.2% devices. Because many Chinese mobile phones have no chance to use the google play market, therefore, the situation in the Chinese market is only known after reading the quarterly report similar to that of umeng. Well, I personally think that devices will have a desire to use them after android 4.0, the previous version was limited by hardware and system optimization. In my opinion, apart from making a phone call, receiving a text message, reading a microblog, and using QQ, there is not much value for people to use. As for the reasons, you will know what you know, and you will not know what you do. now, with the development of hardware technology, we can easily purchase mobile phones and tablets with strong enough performance and cheap enough prices for android 4.0. Now, it is not too late for us to learn the design style of android 4.

Responsive Design

The title of this article is class responsive design, which should be known by some web developers. The so-called responsive design, is a web page can be based on computer access or mobile access to a response to the display, in the google official design guide document, there are also related instructions http://developer.android.com/design/patterns/multi-pane-layouts.html, compared with the responsive design concept of web, android can only be called as a similar concept, because android is simpler than web terminals, in android, you only need to consider when to display a pane and when to display two pane.

Theoretical Basis of Design

To solve the problem of when the android app displays a pane and when, we need to know how android solves compatibility issues in various resolutions.

In the era of desktop software, we seldom find that some people speak out about the situation at different resolutions. As for the reason, I personally think that, first, there are many computer resolutions, however, the dpi/ppi on the screen is similar, which makes the display of measurement parameters in pixels on different screens not very different. Second, that is, the windows of the software on the pc are adjustable, And you rarely see the windows on the mobile phone or tablet (of course, some android devices of Samsung now support this ). however, mobile devices are completely different. First, the compatibility problem arises, rooted in the problem of how big a pixel is to be displayed. On a high-density mobile phone screen, A pixel is displayed very small, so we assume that we want to display a length of about 100 with 2 cm pixels, but only 1 cm is displayed. The second point is, mobile devices do not support Window Scaling. If I define a unit of 100 pixels, there will never be any space for users to adjust. in fact, android has provided a good solution to this problem, that is, it does not rely on the measurement units of pixels and allows the system to render pixels according to the screen density.

One image:

650) this. width = 650; "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0J0015062-0.png "style =" cursor: pointer; "/>

One formula:

Px = dp * (dpi/160)

If you strictly follow the above two points to design your program, then you do not need to worry about resolution compatibility issues. of course, to do this, you need to worry about the design.

Android Program Implementation

I have discussed a bunch of theoretical things above. It is estimated that everyone is tired of reading them. How can I implement it on android?

Design Rules

First, let's look at a figure:

650) this. width = 650; "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0J0013350-1.png "style =" cursor: pointer; "/>

The simplest difference between a mobile phone and a tablet is whether one side of the screen is greater than 600dp. Then we can draw a flowchart.

 

650) this. width = 650; "border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131228/0J001L42-2.png "alt =" "/>

Show one pane or multiple pane

If we put the design of the tablet and mobile phone, we simply think that a pane is displayed on the mobile phone and multiple pane is displayed on the tablet, which is too superficial.

In web design, we have a div concept. For this concept, we can smoothly transition to the design of our android Application. after android 4 is actually android 3, google realized that the charm of the android tablet was not enough for us to develop the tablet for another time (such as iPad, A web-like design scheme is introduced to completely separate each view so that the activity is only a container for these views. Before fragment is launched, we need to make a design, we need a lot of effort, because we need to manually maintain the life cycle of each view, and with fragment, we have a stable mechanism (compatible with packages earlier than Android 4 ). next, we only need to consider how to deal with the entire logic of our application. After studying multiple android-adaptive apps, we come up with a rule about 600dp.

The so-called 600dp Law

We can know from the above that the difference between a mobile phone and a tablet is long or as high as 600dp, so what can this 600dp do? First, 600dp is the separation between the cell phone and the tablet. The biggest difference between the cell phone and the tablet is how much content can be displayed on the screen. If the cell phone is displayed as a pane unit, so for larger than 600dp, we can consider putting one more pane under one screen. (For more information about why 600dp is selected, see google android apps)

Now, we take the open-source Chinese client as an example to explain how to use this rule in practice.

The original client displays the following information on a mobile phone:

650) this. width = 650; "border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131228/0J00152K-3.png "alt =" "/>

The following figure is displayed on a flat panel (with a width greater than 600dp: 

650) this. width = 650; "border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131228/0J0014932-4.png "alt =" "/>

We can easily find that, for devices larger than 600dp, screen utilization is far from enough. Next we will use the 600dp rule for this purpose and display it after the revision.

Display after transformation according to the 600dp rule 

650) this. width = 650; "border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131228/0J00123B-5.png "alt =" "/>

About landscape screens

 

650) this. width = 650; "border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131228/0J00111W-6.png "alt =" "/>

We all know that there seems to be a lot of free space after the mobile phone landscape screen, so can we consider putting multiple pane?

First, we need to consider whether our applications target tablets or mobile phones, rather than how to make good use of the screen space, here, 600dp is the best size for cell phones and tablets. if you want to consider the design of mobile phones and tablets, you only need to consider the differences between an app on mobile phones and tablets. If you want to make good use of screen usage, please design one set based on your phone or tablet.

Recommended books

Http://developer.android.com/guide/practices/screens_support.html

Http://developer.android.com/training/multiscreen/screensizes.html

Online tools

Calculate DPI http://members.ping.de /~ Sven/dpi.html

If anyone has time, do you want to transplant it to runjs for the benefit of the masses... Remember to inform me!

Source code

This project is also open-source. If you want to run it, you need to download the source code of the original osc android app, set the original project to android libs, and then introduce it. if you do not know what the android libs project is, I suggest you go to google. because it is a hobby,Please do not have too many hopes

Https://github.com/youxilua/android-app/tree/0.0.1

This article is from the "game a chai" blog, please be sure to keep this source http://youxilua.blog.51cto.com/3357586/1083555

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.