Android Studio Study Notes

  I'm a mile by mile beeping geek developers up main video learning, still speaks in great detail, for my people that do not learn Java is said can understand. Special thanks up master!

  Today's learning environment to build Android Studio, mainly to install JDK and JRE. Then modify environment variables. Then it is to install Android Studio, with a virtual machine. After the installation had to install Android Studio SDK, I was installed, such as the middle way by downloading a very long time. After installation of the project have established a variety of error, for I do not know English, feel very painful process, and each time I have been wrong translation by Baidu conduct research, and then search for cases encountered the same problem on Baidu, according to their way of suggesting a series of changes after went to great lengths, and finally my development environment to build better.

  Then I learned the first time to record the main video up - to write birthday cards APP, this seemingly simple APP, perhaps for some heavyweights for nothing, but white is just getting started, pretty good, because at least you know that it happened.

  In this video here that I learned

  1) Control TextView (text box)

     android: layout_margin = "20dp" // frame from 20

     android: textSize = "22dp" // font size

     android: textColor = "@ android: color / holo_red_light" // set the font color red

  2) control the ImageView (FIG present block)

     android:layout_centerInParent="true"        //居中

     android: src = "@ drawable / bathdays" // choose to use the picture for the position

  3) Control Button (button)

     android: id = "@ + id / btn" // ID is determined btn

     android: layout_margin = "10dp" // plate margins

     android: layout_alignParentBottom = "true" // put the final

    

Note: The above is purely based on what you get up to learn to understand the main video, the god do not spray, if a better understanding of the trouble to inform, in this very grateful, thank you!

Is to take over Java code, at the beginning I explained that I did not Java-based, so the layout there are these definitions do not quite understand, but still better write down, after learning to understand him always

the extends the MainActivity AppCompatActivity {class public 

@Override
protected void the onCreate (the Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
// display layout of
the setContentView (R.layout.activity_main);

// initializes the topology
intUI ();
}

above should be the main function , the equivalent of C language I learned in the main. Here to do an initial layout, which in addition also learn practical shortcut, Alt + Enter can write directly to the function!
void intUI Private () { 
// get the media player objects
Final MediaPlayer mediaPlayer = MediaPlayer.create (getApplicationContext (), R.raw.music);
// Register the click event
findViewById (R.id.btn) .setOnClickListener (new View . OnClickListener to () {
@Override
public void the onClick (View View) {
IF (mediaPlayer.isPlaying ()) {
mediaPlayer.pause ();
} the else {
mediaPlayer.start ();
}
}
});
}

this put a simple birthday card app ready. Feel good, the future have to look at Java language learning his definition format.



Furthermore, it is the main system to enter up study by the set 0-3, the first few episodes just fine, the time to 03 analog small album a little less understand. So long looked talk about these learning gains
because of this simple birthday card APP tutorial, the first few episodes before with the same.
1. First, learn the knowledge of Android Studio interface. We have established the general understanding of the engineering works on the line chosen Android, (which we used to write code), app and Gradle Scripts.
Under highlight some app here this folder, open the app there are three sub-file, ①manifests②java③res
and we used these three files are ① in AndroidManifest.xml, ②-> layout-> MainActivity, ③layout-> activity_main.xml

first a file is equivalent startup file to configure the project name as well as some of the issues started.
The second file is to become code file, writing some of the main logic.
The third file is the file layout of writing, mainly to put controls (write better code for beginners).

2. Then learn the basic linear layout LinearLayout
android: orientation = "vertical" direction of the vertically aligned vertical linear layout @ | arranged laterally Horizontal

03 is set to the simulated album APP
here we use an ImageView, for displaying the picture
a TextView, a message alert picture
2 Button, for turning the page

<The ImageView 
Android: ID = "@ + ID / iv_show"
Android: layout_width = "match_parent"
Android: layout_height = "50dp"
occupied layout_weight = "1" // remaining control: Android
Android: background = "@ Android: Color / background_dark "/> // set on a black background
   
<TextView
android:id="@+id/tv_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="图片信息"
android:gravity="center"  //居中  
android:padding="10dp"    //内边距
/>
 
<LinearLayout
android:gravity="center"         //居中
android:orientation="horizontal"    //竖直排列
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上一张" />

<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一张" />

</LinearLayout>

/ ******** *************** linear arrangement adopted here two key layout /

These are the ②-> layout-> MainActivity code


took logic code we have to write Java

private ImageView mImage;
private TextView mText;
private int num;
private int index;
private String[] title;
private int[] images;
@Override 
protected void the onCreate (the Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
the setContentView (R.layout.activity_main);
// initialize control
as initView ();
// initialize data
initData ();

}
void initData Private () { 
title = new new String [] { "Nos. 1", "No. 2", "No. 3", "No. 4", "No. 5"};
Images = new new int [] R.drawable.a {, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e};

mImage.setImageResource (Images [0]);
mText.setText (title [0] );

NUM = title.length; // the number of pictures of
index = 0; // index images currently displayed
}
private void initView(){
mImage = findViewById(R.id.iv_show);
mText = findViewById(R.id.tv_show);
findViewById(R.id.btn_previous).setOnClickListener(this);
findViewById(R.id.btn_next).setOnClickListener(this);
}

@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.btn_previous:
//上一张
if(index==0){
index = title.length - 1;
}else {
index--;
}
break;
case R.id.btn_next:
//下一张
if(index==4){
index = 0;
}else{
index++;
}
break;
}
updateImageAndTitle();
}

void updateImageAndTitle Private () { 
mImage.setImageResource (ImagesRF Royalty Free [index]);
mText.setText (title [index]);
}

After the code above to learn, I learn the shortcut keys Ctrl + Alt + F to declare global variables, the other how to I feel almost forgot to catch tomorrow to get another again is how mean, as the Java programming architecture'll have reasonable grounds.




In summary, what I learn Android Studio notes today! ! !

Guess you like

Origin www.cnblogs.com/xiaojian98/p/11925451.html