Knowledge about Android Layout

Source: Internet
Author: User

1. android: layout_width = "0.0dip"

Description: The display size is 0. That is, it is not displayed. If it is an advertisement or other pop-up window, the command is set to 0.0dip and will not be displayed on the program page.

2. Relative layout: RelativeLayout

RelativeLayout allows child elements to specify their positions relative to their parent or sibling elements, which is one of the most common layout methods in actual layout. It has a lot of flexibility. Of course, there are also many attributes, and the operation is difficult. There is also a high possibility of conflicts between attributes. When using relative layout, more tests are required.

The following are common attributes:

Some important attributes used by RelativeLayout:

Class 1: the property value is true or false.

Android: layout_centerHrizontal horizontal center

Android: layout_centerVertical vertical center

Android: layout_centerInparent is completely centered over the parent Element

Android: layout_alignParentBottom: attach the lower edge of the parent Element

Android: layout_alignParentLeft: Stick the left edge of the parent Element

Android: layout_alignParentRight: attaches the right edge of the parent element.

Android: layout_alignParentTop: top the parent Element

Android: layout_alignWithParentIfMissing

Class 2: the property value must be the reference name "@ id/id-name" of the id"

Android: layout_below is under an element

Android: layout_abve is above an element.

Android: layout_toLeftOf on the left of an element

Android: layout_toRightOf on the right of an element

Android: layout_alignTop: Align the top edge of an element with the top edge of an element.

Android: layout_alignLeft: Align the left edge of an element with the left edge of an element.

Android: layout_alignBottom: the bottom edge of the current element is aligned with the bottom edge of an element.

3. android: layout_alignRight: Align the right edge of an element with the right edge of an element.

Category 3: attribute values are specific pixel values, such as 30dip and 40px.

Android: layout_marginBottom distance from the bottom edge of an element

Android: layout_marginLeft distance from the left edge of an element

Android: layout_marginRight distance from the right edge of an element

Android: layout_marginTop distance from the edge of an element

Android: hint of EditText

Prompt information in the input box when EditText is set to null.

Android: gravity

Android: gravity attribute is a limitation on the view content. for example, text on a button. you can set the text to the left and right of the view. take the button as an example. For android: gravity = "right", the text on the button is right-aligned.

Android: layout_gravity

Android: layout_gravity is used to set the location of the view relative to its parent view. for example, if a button is in linearlayout, you can set it by placing it on the left or right. take the button as an example. For android: layout_gravity = "right", the button is right-aligned.

Android: layout_alignParentRight

Align the right end of the current control with the right end of the parent control. The attribute value can only be true or false. The default value is false.

Android: scaleType:

Android: scaleType controls how images are resized/moved to match the size of ImageView. ImageView. ScaleType/android: the differences between scaleType values:

CENTER/center is centered according to the original size of the image. When the length/width of the image exceeds the length/width of the View, the CENTER part of the captured image is displayed.

CENTER_CROP/centerCrop scales up the image size in the center, so that the image length (width) is equal to or greater than the View length (width)

CENTER_INSIDE/centerInside shows the entire content of the image in the center. The image length/width is equal to or less than the View length/width by proportional reduction or the original size.

FIT_CENTER/fitCenter scales up/down the image proportionally to the width of the View and center the image.

FIT_END/fitEnd: scales up or down an image to the width of the View, which is displayed in the lower part of the View.

FIT_START/fitStart scales up/down an image proportionally to the width of the View.

FIT_XY/fitXY increase or decrease the image size proportionally to the View size.

MATRIX/matrix is drawn using a MATRIX to dynamically zoom in and zoom in images.

** Note that the names of images in the Drawable folder cannot be capitalized.

3. selector background selector of android

Listview and button change the background of the original android control in different States and use the selector background selector.

The following describes the application of selector background selector:

(1) android selector is configured in drawable/xxx. xml.

For example:

Android: drawable = "@ drawable/pic2"/>

Android: drawable = "@ drawable/pic3"/>

(2) Use the above xml file method:

First, configure android: listSelector = "@ drawable/list_item_bg" in listview"

The second method is to add the property android: background = "@ drawable/list_item_bg" to the listview item.

The third method is to use Drawable drawable = getResources (). getDrawable (R. drawable. list_item_bg) in java code );

ListView. setSelector (drawable); same effect.

However, sometimes the list is black. You need to add android: cacheColorHint = "@ android: color/transparent"

Make it transparent.

(3) You can set selector to change the text status in the button.

Use the android: color attribute to set

For example:

(4) The Button can also achieve more complex effects, such as gradient.

For example:

Android: bottom = "10dp" android: right = "10dp"/>

Android: bottom = "10dp" android: right = "10dp"/>

Finally, you need to add two items to the xml file containing the button.

Android: focusable = "true"

Android: backgroud = "@ drawable/button_color"

4. ScrollView usage

(1) ScrollView and HorizontalScrollView Add a scroll bar for the control or layout.

(2) The two controls can only have one child, but they are not containers in the traditional sense.

(3) The two controls can be nested with each other.

(4) The position of the scroll bar can be set by layout_width and layout_height.

(5) ScrollView is used to set the vertical scroll bar. HorizontalScrollView is used to set the horizontal scroll bar. Note that one attribute is that scrollbars can set the direction of the scroll bar: however, setting ScrollView to horizontal is the same as setting it to none, and setting HorizontalScrollView to vertical and none has the same effect.

5. android Developers set borders for linearlayout

(1) first create an xml file in the res directory, select drawable as the type, and a drawable file will be generated one by one (My sdk is android 4.1) and an xml file will be generated, write the following code:

Android: width = "0.01dp"

Android: color = "# FFFFFF"/>

Android: bottom = "1dp"

Android: left = "0.5dp"

Android: right = "0.5dp"

Android: top = "0dp"/>

(2) Add android: background = "@ drawable/boder" to the xml command of the control for setting borders"

6.

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.