"Android App Development technology: User Interface" user interface layout Tips

Source: Internet
Author: User

Guo Xiaoxing
Weibo: Guo Xiaoxing's Sina Weibo
Email:[email protected]
Blog: http://blog.csdn.net/allenwells
Github:https://github.com/allenwell

This article describes some techniques for making the layout more reasonable and efficient.

Make the control fill the remaining width or height

A edittext and a button are defined as shown:

This is appropriate for the button, but not good for text boxes, because users may enter longer text content. So it's better to be able to fill the entire screen width. LinearLayout use the property of the weight to achieve this, you can set it using the Android:layout_weight property.

You can specify the size of the weight value based on the space occupied by each part, and its total number is determined by the same level of components. It is similar to the composition of the drink: "Two vodka, one coffee liqueur", which means that the vodka in the wine accounted for two-thirds. For example, if you set a view with a weight of 2 and another view with a weight of 1, then the total is 3, when the first view occupies 2/3 of the space and the second occupies 1/3 of the space. If you add a third view and the weight is set to 1, then the first view (with a weight of 2) occupies 1/2 of the space, and the remaining two view accounts for 1/4. (Note that the premise of the use of weights is generally set to 0DP for the width or height of the view, then the system calculates the space that the view should occupy according to the weight rules above.) However, in many cases, if the view is set to the Match_parent attribute, then the above calculation of the weight is not usually proportional to, but the inverse ratio, that is, the weight of large but occupy a small space. For all view default weights is 0, if you only set a view with a weight greater than 0, then this view will occupy all the remaining space to remove the space occupied by the other view itself. The weight of the edittext is therefore set to 1 so that it can occupy all the space except for the button.

In order to improve the efficiency of the layout, when setting weights, you should set the width of the edittext to 0DP. If you set the "Wrap_content" as the width, the system needs to calculate the width of the part itself, and because you set the weight, so the system will automatically occupy the remaining space, the width of the edittext eventually become a non-functional properties.

The effect of the change is as follows:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Android App Development technology: User Interface" user interface layout Tips

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.