"Android Interview Treasure" study notes (Chapter II: Layout)

Source: Internet
Author: User

How do I get three buttons to align left, center, and right in the horizontal direction separately?

Android:layout_gravity= "left"

Android:layout_gravity= "Center_horizonal"

Android:layout_gravity= "Right"

How do I get the width and height of a component?

Call the View.measure method to measure the width and height of the component before calling View.getmeasuredwidth and View.getmeasuredheight (layout is also a subclass of view)

How do I make five buttons in a plum blossom-like arrangement?


How do I determine the location coordinates of a view?

int[] location = new Int[2];
View.getlocationinwindow (location);//Gets the absolute coordinates within the current window
View.getlocationonscreen (location);//get absolute coordinates across the screen
Location [0]--->x coordinates, location [1]--->y coordinates

How do I control control properties with Java code?

You first create a Layoutparams object, set the property with Layoutparams.addrules, and finally call the View.setparams method.

The use of tablelayout?

The tabular layout model manages child controls in the form of rows and columns, each of which behaves as a TableRow object, or, of course, a View object. TableRow you can add child controls, one for each column.

How will view?

View.setdrawingcacheenabled ()

View.getdrawingcache ()

How do I set the background color of a window to a gradient color?

GetWindow (). setbackgrounddrawable (gradientdrawable);

What does the Layout_weight attribute mean?


What are the effects of padding and Layout_margin properties?

padding: Sets the distance between the contents of the view and the left and right four directions from the edge.

Layout_margin: Sets the distance of the view's edge from other view or parent containers.

Dimensions of the unit of measurement?

PX, in, MM, PT (one point, 1/72 inch), DP, SP

The width of the entire screen is 160DP

SP is suitable for setting text size

The difference between layout_gravity and gravity?

layout_gravity Specifies the position of the current view in the parent container, gravity specifies the location of the content in the view.

How do I reuse a layout file?

Use <include> tags.

Layout optimization:


"Android Interview Treasure" study notes (Chapter II: Layout)

Related Article

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.