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

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

<?xml version="1.0" encoding="utf-8"?>
    <!--定义android的命名空间-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="yiwei.com.networktest"> 
       <!--指定本应用内java主程序的包名,这里就是yiwei.com.networktest-->
<!--权限声明-->
<uses-permission android:name="android.permission.INTERNET"/>
    <!--application声明了一个应用程序的组件及其属性-->
   <!--allowBackup 将程序加入到系统的备份和恢复架构中-->
    <!--icon表示APP的图标-->
    <!--label 许可列表-->
    <!--supportsRtl启用各种RTLAPI来用RTL()由右到左的语言和阅读方向)布局显示应用-->
    <application
                android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
        android:theme="@style/AppTheme">
    <!--android:name表示当前的activity的名字-->
        <activity android:name=".MainActivity">
            <!--intent-filter:包含了action,data和category三种。-->
            <!--action:只有android:name属性,常见的是android.intent.action.MAIN,表示此activity是作为应用程序的入口。-->
            <!--data:指定了希望接受的intent请求的数据URI和数据类型。-->
            <!--category:android:name属性,常见的是android.intent.category.LAUNCHER,决定应用程序是否显示在程序列表里。-->
            <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;
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值