Android layout tips, basic knowledge collection

Source: Internet
Author: User

This article constantly updated, used to record the usual layout related to the useful points, here to share to everyone, if there is a mistake to say, thank you.

1, the ListView Add button and other things, you can set the ListView properties Android:layout_weight= "1" and then you can display.

2, two buttons filled with a line, you can set the property android:layout_weight= "1". You can split the display.

3. The difference between android:gravity and android:layout_gravity:

Android:gravity is where the child controls are arranged in the current control

Android:layout_gravity is the placement position for the current control in the parent control

For example, a control button:android:layout_gravity represents the position of the button on the interface. The android:gravity represents the position of the word on the button on the button.


4, relativelayout Some important attributes, through the following properties can achieve a lot of layout effect

Android:layout_centerinparent Center Layout
Android:layout_centervertical Vertical Center Layout
Android:layout_centerhorizontal Horizontal Center Layout
Android:layout_alignparenttop in the top of the container
Android:layout_alignparentbottom in the bottom of the container
Android:layout_alignparentleft in the left side of the container
Android:layout_alignparentright in the right side of the container

Android:layout_above above the specified view
Android:layout_below below the specified view
Android:layout_torightof on the right side of the specified view
Android:layout_toleftof on the left side of the specified view
Android:layout_aligntop is consistent with top of the specified view

5. Android TextView There is an attribute with an ellipsis in the contents of the ellipsize , Use the following in XML :

Android:ellipsize = "End" ellipsis at the end
Android:ellipsize = "Start" ellipsis at the beginning
Android:ellipsize = "Middle" ellipsis in the middle
Android:ellipsize = "marquee" marquee
Android:singleline = "true"


6, Android button set the color is different before and after the click

Create a new drawable folder in the Res directory, this folder is resolution-independent, and then create a new Button_selector.xml file in this folder, the root node is selector oh.

When you are new, modify the entire file contents to look like this:

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">        <item android:drawable=" @color/button_normal "android:state_pressed=" false "/>        < Item android:drawable= "@color/button_pressed" android:state_pressed= "true"/></selector>
Then create the Colors.xml file in the Res/values directory with the following contents:

<resources>    <color name= "Button_normal" > #2464A9 </color>    <color name= "button_pressed "> #0099FF </color></resources>

Then in the layout file, locate the button that you want to add the effect to, and add the following properties:

        android:background= "@drawable/button_selector"
Well, the effect we need is done.


Android layout tips, basic knowledge collection

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.