第一章:第一行android代码注解(4)

Packages工程
1.AndroidManifest.xml
这是整个Android项目的配置文件,在程序中定义的所有四大组件都需要在这个文件里注册。另外还可以在这个文件中给应用程序添加权限声明等。


    
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="yiwei.com.networktest"> 
       

<uses-permission android:name="android.permission.INTERNET"/>
    
   
    
    
    
    <application
                android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
        android:theme="@style/AppTheme">
    
        <activity android:name=".MainActivity">
            
            
            
            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            intent-filter>
        activity>
    application>

manifest>

2.layout的activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    tools:context=".HelloWorldActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
RelativeLayout>
`RelativeLayout:相对布局。
xmlns:android定义:android命名空间。
xmlns:tools:tools命名空间,用来预览一些布局属性的添加和删除后的效果。
android:layout_width:指定了控件的宽度,可选择match_parent,fill_parent,wrap_content,顾名思义,match匹配的意思,wrap包裹的意思,即match_parent表示让当前控件的大小和父布局的大小一样,也就是由父布局来决定当前控件的大小。wrap_content表示让当前控件的大小能够刚好包含住里面的内容,也就是由控件内容决定当前控件的大小。
android:layout_height:同上。
android:paddingLeft,android:paddingRight,android:paddingTop,android:paddingBottom:站在父view的角度描述问题,它规定它里面的内容必须与这个父view边界的距离。此外还有margin,它是站在自己的角度描述问题,规定自己和其他的view之间的距离,如果同一级只有一个view,那么它的效果基本上就和padding一样了。padding填充; 补白; 边距; [ˈpædɪŋ] 
TextView:android的控件,用于在布局中显示文字的。
                android:text:textview显示的内容,这里就是hello world了。
 3.MainActivity.java
 package com.test.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class HelloWorldActivity extends Activity {
//HelloWorldActivity 继承Activity,Activity是Android系统的一个活动基类,所有的活动都必须要继承它才能拥有活动的特性
    @Override
    //onCreate()方法是一个活动被创建时必定要执行的方法
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //加载布局
        setContentView(R.layout.hello_world_layout);
        Log.d("HelloWorldActivity", "onCreate execute");
    }


    @Override
    //创建菜单
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.hello_world, menu);
        return true;
    }

}

你可能感兴趣的:(第一行代码注解)