Android Development Notes 1.2 Test Development Environment

one

  • After installing the Android integrated development environment, we must learn to create Android applications and understand the MVC architecture of Android applications - control layer: write code in MainActivity to control program logic, view layer: design the user interface in activity_main, and model layer: strings. Define string data in xml.

(1) Create Android applications

  • Create a new Android project
    Insert image description here

  • Based on Empty ActivitytemplateInsert image description here

  • Configure basic project information
    Insert image description here

  • Click the [Finish] button
    Insert image description here

(2) Running Android applications

  • Click the green run button on the toolbar
    Insert image description here
  • Start the simulator and view the program running results
    Insert image description here
  • There is a label in the center of the screen -Hello World

(3) Set screen labels

1. Modify label text attributes

  • Open the res\layout directory and open the main layout file activity_main.xml. The default is Design view.
    Insert image description here

  • Switch to Code view
    Insert image description here

  • Modify android:textattribute value
    Insert image description here

  • Restart the application and see the effect
    Insert image description here

  • Looking at the screen prompts, it is recommended not to use hardcoded strings (Hardcoded string) and should use @string resources.
    Insert image description here

  • So we need to define a string variable in the file res/valuein the directorystrings.xmlwelcome
    Insert image description here

  • activity_main.xmlCall this string variable in the layout configuration filewelcome
    Insert image description here

2. Set the label font size and color

  • Modify label font size and color, textSize - text font size; textColor - text color
    Insert image description here
  • Restart the app and see the effect
    Insert image description here

3. Modify the application title

  • Find the Android app we created in the app list -Test
    Insert image description here
  • The program runs and the title on the activity bar is also the name of the application -Test
  • app_nameModify the value of a string variable in a string resource file
    Insert image description here
  • Restart the app and see the effect
    Insert image description here
  • Close the app and view the app list
    Insert image description here

(4) Modify the layout and set layout properties

1. Change constraint layout to linear layout

  • Change ConstraintLayout to LinearLayout
    Insert image description here

2. Set linear layout properties

(1) Set background image
  • Official documentation: Ordinary pictures are placed in the drawable directory, and icons are placed in the mipmap directory.
    Insert image description here

  • Copy the background image background.png to the drawable directory
    Insert image description here

  • backgroundSet properties for linear layout
    Insert image description here

  • Run the program and see the effect
    Insert image description here

(2) Set the alignment of sub-controls
  • Set the linear layout gravityproperties tocenter
    Insert image description here

  • Run to see the effect
    Insert image description here

(3) Set the linear layout direction
  • If you want to add multiple label controls to a linear layout, the default is to arrange them horizontally, that is, the orientation property of the linear layout defaults to horizontal. If you want to arrange vertically, then the orientation attribute of the linear layout must be set to vertical.
    Insert image description here
  • Add a label and set related attributes
    Insert image description here
  • Run the program and see the effect
    Insert image description here
  • If you want the two labels to be separated by a little, then set the margin attributes (marginLeft, marginRight, marginTop, marginBottom)
    Insert image description here

2. Computer operation

(1) Write the main layout file

Insert image description here

(2) Writing string resource files

Insert image description here

(3) Run the program to see the effect

Insert image description here

Guess you like

Origin blog.csdn.net/qq_41301333/article/details/127762975