Android Studio Getting Started--002 control Chapter

Source: Internet
Author: User

Recently read the book is the first line of code the teacher recommended-the feeling of speaking very basic, very small white appetite. All right, no more wordy, dry goods.

------------------------------------------------------------------------------------------------------------

Control Chapter

1.TextView This is a simple control---used to display some textual information on the page "The property that this control must declare--width, height, content, id"

2.Button is an important control that the program uses to interact with the user--those basic attributes and Terxtview almost the only one is the android:onclick= "FuncName" [This point, the basics of space don't need much understanding, Feel the way the event is handled more simply]

3.EditText---A control that interacts with a user---a simple-based control is better implemented in Androidstudio, directly giving an ID, width, or height to the basic needs of a space, and then adding special properties to different controls. Back to the special point in this edittext is the initial input box control of the prompt text--android:hint= "text" and a set maximum number of rows "guaranteed input more edittext will not continue to stretch"

4.imageview--First picture resources placed under the Drawable folder, so that the file name in the following can be directly r.drawable.name to obtain the corresponding file.

5.progressbar--for the interface to display a progress bar "can use style to change the style of the progress bar"

6.alertdialog--in this note is to write the Cancel and OK button time processing method

7.progressdialog--displays a dialog box with a progress bar

----above are "basically all" basic controls, the next step is to understand the layout of these controls, more in-depth beautification of their own interface--------------------------------------

Layout method

What is a layout? A layout is a container for placing controls that can adjust the position of the internal space according to certain rules to achieve the fine interface that you want to achieve.

1. Linear Layout LinearLayout

A linear layout Arranges the space it contains in a linear direction.

One of the most important attributes of a linear layout is: Android:weight "sets the weight of the corresponding control and then calculates the width" example: When a EditView and button control are arranged horizontally, different phone screens are not the same size. However, the size of the button you want to design does not change. Then the width of the button is set to the width of the wrap_content,editview with a weight of 1 to be able to perfectly display the design of the button without it being stretched, affecting the appearance.

2. Relative layout relativelayout This layout is more casual, it makes the space appear where you want it by relative positioning---this layout is useful for controls that have relative positional relationships.

android:layout_alignparentleft= "bool" android:layout_abolve/below/toleftof/torightof= "@id/id"//This is obtained by ID to the control

3. Frame layout This layout is simple with respect to the previous two, and the application scenario is much less. This layout is not conveniently positioned, and all controls are placed by default in the upper-left corner of the layout.

4. Percent layout take a closer look at the top three layouts, and linearlayout support for scaling the size of the control

But the percent layout is not the default layout, so the layout is already defined in the support library, and all we need to do is to build.gracdle the file.

dependencies{

Compile Filetree (dir: ' Libs ', include:[' *.jar '])

Compile ' com.android.support.appcompat-v7:24.2.1 '

Compile ' com.android.support:percent:24.2.1 '//Add this line of code in this closure

Testcompile ' junit:junit:4.12 '}

You need to write out all the file paths when using the hundred-percent layout <android.support.percent.percentframelayout></ Android.support.percent.percentframelayout>

In this case, you can create the size of the control directly using percentages.

Summary: After a careful look at this layout, the individual thinks that the percentage layout can be replaced by the use of weight in the layout of linear layouts. "Of course, it can be that they have no real practice, but also do not know the benefits of the distribution of the Hundred"

5. Custom layout Introduction Layout---for activities that have the same controls, consider packaging those basic controls as a layout, and then each activity simply refers to the layout. Thus saving the amount of code is certainly more convenient.

The first step, of course, is to customize a layout-create the layout, named title, and then refer to this fixed-mode layout in the new layout--<include layout= "@layout/title>

Go to bed

Android Studio Getting Started--002 control Chapter

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.