Android基础-01

Android基础-01

1.1G-4G的介绍

2.Android操作系统介绍

3.Android历史介绍

4.Android系统架构(重点)

系统架构的四个层次:

1、应用程序层:自己的开发应用程序都是运行在这一层;
2、框架层:开发应用程序使用的API都在这一层;
3、类库层:基础类库;
4、linux内核:

5.两种虚拟机的不同(重点)

JVM与Dalvik虚拟机之间的区别:

1、JVM加载的是.class文件、Dalvik加载的是.dex;
2、JVM加载数据时使用栈架构、Dalvik使用寄存器;

6.SDKManger的使用

AVD:Android virtual Device;

VGA 480* 640
QVGA 240*320
HVGA 320*480
WQVGA 240*400
FWVGA 480*854
WVGA 480*800
AVD: Android virtual Device

7.模拟器的简介及创建

adb Android debug bridge:安卓调试桥;

8. AVD的创建

9.DDMS介绍

DDMS:

Dalvik Debug Monitor Service Dalvik虚拟机的调试监听服务;
Debug Device Monitor Service 设备的监听服务;
Device Definition Monitor Service 设备定义的监听服务;

10.SDK目录

11.创建HelloWorld

安装的过程:

eclipse运行应用程序时,先去编译工程,打包成一个apk。使用adb把apk文件上传到设备上,设备会自动安装apk,安装完成后自动开启第一个界面。

12.Android目录结构(重点)

src/  java源代码存放目录
gen/ 自动生成目录
gen 目录中存放所有由Android开发工具自动生成的文件。目录中最重要的就是R.java文件。 这个文件由Android开发工具自动产生的。Android开发工具会自动根据你放入res目录的资源,同步更新修改R.java文件。正因为R.java文件是由开发工具自动生成的,所以我们应避免手工修改R.java。R.java在应用中起到了字典的作用,它包含了各种资源的id,通过R.java,应用可以很方便地找到对应资源。另外编绎器也会检查R.java列表中的资源是否被使用到,没有被使用到的资源不会编绎进软件中,这样可以减少应用在手机占用的空间。
res/ 资源(Resource)目录
在这个目录中我们可以存放应用使用到的各种资源,如xml界面文件,图片或数据。具体请看ppt下方备注栏。
libs/ 支持库目录
程序开发时需要的一些三方的jar包可以放在这个目录,系统会自动把里面的jar包,添加到环境变量。
assets资源目录
 Android除了提供/res目录存放资源文件外,在/assets目录也可以存放资源文件,而且/assets目录下的资源文件不会在R.java自动生成ID,所以读取/assets目录下的文件必须指定文件的路径,如:file:///android_asset/xxx.3gp
AndroidManifest.xml 项目清单文件
 这个文件列出了应用程序所提供的功能,以后你开发好的各种组件需要在该文件中进行配置,如果应用使用到了系统内置的应用(如电话服务、互联网服务、短信服务、GPS服务等等),你还需在该文件中声明使用权限。
project.properties 项目环境信息,一般是不需要修改此文件

13.Android的打包过程

14.ADB命令

adb devices  列出所有的设备、连接上已经设备;

adb devices  列出所有的设备

adb shell 挂载到linux的空间 

adb install xxx.apk 如果有多个设备,我们可以指定设备   adb install –s  emulator-5554 D:/xxx.apk

emulator –avd advname  启动模拟器    例如:emulator –avd 2.2 (2.2 为我们创建设备的名称)

mksdcard 20m d:/sdcard.img 创建sdcard

adb pull <remote> <local> 

adb push <local> <remote>

android create avd –name android2.2 –target 8  创建模拟器

ctrl + F11 横竖屏的切换 

15.电话拨号器(重点)

步骤:

1、理解需求:
2、参考效果图设计UI界面:
3、写代码:

代码:

布局文件:

<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >

<EditText 
     android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/et_phone"
    android:hint="请输入电话号码"
    />


<Button 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
    android:text="拨打"
    android:onClick="call"
    />

</LinearLayout>

MainActivity.java:

package com.itheima.phonecall;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends Activity {

    private EditText et_phone;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化控件
        et_phone = (EditText) findViewById(R.id.et_phone);
    }

    public void call(View view){

        String phone = et_phone.getText().toString().trim();

        if(TextUtils.isEmpty(phone)){
            Toast.makeText(this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
        }else{
            //拨打电话号码
            Intent intent = new Intent();
            //设置 拨打电话的动作
            intent.setAction(Intent.ACTION_CALL);
            //设置数据
            intent.setData(Uri.parse("tel://"+phone));
            //调用拨打电话号码的功能
            startActivity(intent);

        }
    }


}

配置文件:

在清单文件中添加权限:
     <uses-permission android:name="android.permission.CALL_PHONE"/>

16.四种点击事件

1、内部类的方法:

(1)在布局文件中定义按钮的ID:
    <Button 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
    android:text="拨打"
    android:id="@+id/bt"
    />
(2)在代码中给按钮添加监听事件:
    private EditText et_phone;
    private Button bt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化控件
        et_phone = (EditText) findViewById(R.id.et_phone);
        bt = (Button) findViewById(R.id.bt);

        bt.setOnClickListener(new OnClickListener() {

            //点击按钮之后才会调用这个方法
            @Override
            public void onClick(View v) {
                String phone = et_phone.getText().toString().trim();

                if(TextUtils.isEmpty(phone)){
                    Toast.makeText(MainActivity.this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
                }else{
                    //拨打电话号码
                    Intent intent = new Intent();
                    //设置 拨打电话的动作
                    intent.setAction(Intent.ACTION_CALL);
                    //设置数据
                    intent.setData(Uri.parse("tel://"+phone));
                    //调用拨打电话号码的功能
                    startActivity(intent);

                }

            }
        });
    }

2、自定义一个监听器类:

private class MyListener implements OnClickListener{

@Override
public void onClick(View v) {
    //点击按钮之后才会调用这个方法
        String phone = et_phone.getText().toString().trim();

        if(TextUtils.isEmpty(phone)){
            Toast.makeText(MainActivity.this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
        }else{
            //拨打电话号码
            Intent intent = new Intent();
            //设置 拨打电话的动作
            intent.setAction(Intent.ACTION_CALL);
            //设置数据
            intent.setData(Uri.parse("tel://"+phone));
            //调用拨打电话号码的功能
            startActivity(intent);
        }

}

}

3、在布局文件中给按钮添加一个单击事件的响应方法,然后再中添加一个方法:

布局文件:
    <Button 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
    android:text="拨打"
    android:onClick="call"
    />
代码:
    public void call(View view){

    String phone = et_phone.getText().toString().trim();

    if(TextUtils.isEmpty(phone)){
        Toast.makeText(this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
    }else{
        //拨打电话号码
        Intent intent = new Intent();
        //设置 拨打电话的动作
        intent.setAction(Intent.ACTION_CALL);
        //设置数据
        intent.setData(Uri.parse("tel://"+phone));
        //调用拨打电话号码的功能
        startActivity(intent);

    }
}

4、是activity实现OnClickListener接口,重新onClick方法:

public class MainActivity extends Activity implements OnClickListener{

    private EditText et_phone;
    private Button bt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化控件
        et_phone = (EditText) findViewById(R.id.et_phone);
        bt = (Button) findViewById(R.id.bt);

        //添加单击事件的监听器
        bt.setOnClickListener(this);
    }

    //实现接口的方法
    public void onClick(View v) {
        String phone = et_phone.getText().toString().trim();

        if(TextUtils.isEmpty(phone)){
            Toast.makeText(MainActivity.this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
        }else{
            //拨打电话号码
            Intent intent = new Intent();
            //设置 拨打电话的动作
            intent.setAction(Intent.ACTION_CALL);
            //设置数据
            intent.setData(Uri.parse("tel://"+phone));
            //调用拨打电话号码的功能
            startActivity(intent);
    }
}

17.框架布局

框架布局:framelayout: 摆放空间的时候是把第一个空间放到最下面,最后一个控件显示在最上面;

示例:

<FrameLayout 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"

tools:context=".MainActivity" >

<Button
    android:layout_width="300dip"
    android:layout_height="300dip"
    android:background="#ff0000"
    android:text="@string/hello_world" />

<Button
    android:layout_width="200dip"
    android:layout_height="200dip"
    android:background="#00ff00"
    android:text="@string/hello_world" />

 <Button
    android:layout_width="100dip"
    android:layout_height="100dip"
    android:background="#0000ff"
    android:text="@string/hello_world" />
</FrameLayout>

18.线性布局(重点)

线性布局的方向有两种:垂直、水平; 垂直:把每个控件摆放成一行; 水平:在同一行摆放所有的控件;

示例:

<LinearLayout 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:orientation="horizontal"
tools:context=".MainActivity" >

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ff0000"
    android:text="@string/hello_world" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#00ff00"
    android:text="@string/hello_world" />

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#0000ff"
    android:text="@string/hello_world" />
</LinearLayout>

19.相对布局(重点)

相对布局:其他控件在摆放的时候都是参考某个控件的相对位置来摆放;

示例:

<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"
tools:context=".MainActivity" >

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ff0000"
    android:text="@string/hello_world" 
    android:id="@+id/first_bt"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#00ff00"
    android:layout_toRightOf="@id/first_bt"
    android:text="@string/hello_world"
    android:id="@+id/second_bt" />

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#0000ff"
    android:layout_below="@id/second_bt"
    android:text="@string/hello_world" />

</RelativeLayout>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。