`

Android游戏开发入门小结

 
阅读更多

 

Android游戏开发入门小结

                                                             ——入门者参考

 

学习Android软件开发我首先感觉Android工程比我们以前写的java工程更加复杂,文件更多,但是当清楚每个文件时干嘛用的时候我发现Android开发不是那么的复杂,仅仅是文件多了而已,下面我以一个“helloword”工程为例,谈谈我对Android工程各个文件的理解。

src文件自然不用说了;gen目录下的R文件存放的是工程所用到的组件及图片等的id地址,便于我们调用;res目录下的drawable用来存放图片的;layout是布局文件;values文件是我们会用到的数据;当我们每new一个activity或者server的时候我们都需要在AndroidManifest.xml文件中添加说明。

       在一个布局文件中我们可以添加各种组件,每个布局文件就相当于一个屏幕,在每个组件中我们可以设置其属性,定义其id,便于在java Class中调用。另外,每个我们也可以设置整个屏幕的属性,布局。

       Activity中我们可以得到组件,然后给各个组件进行处理,例如添加监听器等等。千万别忘了在AndroidManifest中添加新的activity哦。

 

   

 

接下来就是代码部分了

 

package first.hello;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class FirstActivity extends Activity {

	//组件声明,定义属性
	private Button bu_reset,bu_login;
	private EditText et_userName,et_passWord;
	
    //程序入口
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //显示界面
        setContentView(R.layout.main);
        //获取组件
        getView();
        
        bu_login.setOnClickListener(listener);
        bu_reset.setOnClickListener(listener);    
    }
    
    /**
     * 获取屏幕上的组建对象的方法
     */
    public void getView(){
    	et_userName=(EditText)findViewById(R.id.et_userName);
    	et_passWord=(EditText)findViewById(R.id.et_passWord);
    	bu_login=(Button)findViewById(R.id.bu_login);
    	bu_reset=(Button)findViewById(R.id.bu_reset);
    }
    
    
    //创建监听器
    OnClickListener listener=new OnClickListener(){
    	public void onClick(View v){
    		//获取被点击按钮的id
    		int id=v.getId();
    		switch(id){
    			case R.id.bu_login:
    				System.out.println("userName=="+et_userName.getText()+"  passWord=="+et_passWord.getText());
        			if("aaa".equals(et_userName.getText().toString())&&"aaa".equals(et_passWord.getText().toString())){
        				//提示信息
        				//Toast.makeText(FirstActivity.this, "登陆成功", 3).show();
        				//创建intent对象,相当于信使rna
        				Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
        				//传参数
        				intent.putExtra("userName", et_userName.getText().toString());
        				//跳转
        				startActivity(intent);	
        			}else{
        				//提示信息
        				Toast.makeText(FirstActivity.this,"登录失败",3);	
        			}
    				break;
    			case R.id.bu_reset:
    				//清空
    				et_userName.setText("");
    				et_passWord.setText("");
    				break;
    			
    		}
    	}
    };
     
    
}

 

 

 

 

 

package first.hello;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class SecondActivity extends Activity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//显示界面
		setContentView(R.layout.second);
		
		//获取Intent对象
		Intent intent = getIntent();
		//获取参数
		String username = intent.getStringExtra("userName");
		//得到文本组件,并设置其文本
		TextView tv_userName = (TextView)findViewById(R.id.tv_userName);
		tv_userName.setText(username);
	}
}
 

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
    

    
        
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/userName"
    />
    
  
<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/et_userName"
    android:textSize="30dip"
    />
    
    

      
        <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/passWord"
    />
   
   
<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/et_passWord"
    android:textSize="30dip"
    />
    


    


    
    <Button
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="reset"
	android:id="@+id/bu_reset"
	/>
	
	<Button
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="login"
	android:id="@+id/bu_login"
	/>
    
</LinearLayout>
 

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  
      <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tv_userName"
    />
  
  
  
  
  
  
</LinearLayout>
 

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="first.hello"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="FirstActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
		<activity android:name=".SecondActivity" 
		/>

    </application>
</manifest>
 

 

分享到:
评论

相关推荐

    android开发入门与实战(下)

    第2章 工欲善其事 必先利其器——搭建Android开发环境 2.1 开发Android应用前的准备 2.1.1 Android开发系统要求 2.1.2 Android软件开发包 2.1.3 其他注意事项 2.2 Windows开发环境搭建 2.2.1 JDK、Eclipse、Android...

    android开发入门教程

    目录 第1章 掀起你的盖头来——初识Android 1.1 认识Android 1.2 Android的背景 1.2.1 Android的历史 1.2.2 Android的发展 1.3 我的Android我做主 1.3.1 开发基于Android平台的应用 ...4.6 本章小结

    android开发入门与实战(上)

    第2章 工欲善其事 必先利其器——搭建Android开发环境 2.1 开发Android应用前的准备 2.1.1 Android开发系统要求 2.1.2 Android软件开发包 2.1.3 其他注意事项 2.2 Windows开发环境搭建 2.2.1 JDK、Eclipse、Android...

    Android开发应用从入门到精通光盘

    Android开发应用从入门到精通 朱桂英 中国铁道出版社 本书循序渐进地讲解了android技术的基本知识,并通过实例直观地演示了android在各个领域中的具体应用。本书内容新颖、知识全面、讲解详细,全书分为4篇17章,第...

    《Google Android开发入门与实战》.pdf

     本书内容上涵盖了用android开发的大部分场景,从android基础介绍、环境搭建、sdk介绍、market使用,到应用剖析、组件介绍、实例演示等方面。从技术实现上,讲解了5个android平台下的完整综合实例及源代码分析,...

    Android 4游戏编程入门经典

    第4章 面向游戏开发人员的android  4.1 定义一个android应用程序:清单文件  4.1.1 [manifest]元素  4.1.2 [application]元素  4.1.3 [activity]元素  4.1.4 [uses-permission]元素  4.1.5 [uses-feature]元素...

    [14本经典Android开发教程]-7-Android编程入门教程

    [14本经典Android开发教程]-6-Android驱动开发入门及手机案例开发分析教程 http://download.csdn.net/detail/cleopard/8388019 剩余8本稍后上传!@或直接从这里寻找@ http://download.csdn.net/user/cleopard/album...

    android游戏编程入门

    android游戏编程入门 《Android4游戏编程入门经典》是2012年清华大学出版社出版的图书,作者是(美)策希纳(Zechner,M.),无(美)格林(Green,R.)。 第1章 Android,后起之秀 1  1.1 Android简介 1  1.2 版本分裂 3 ...

    Google.Android开发入门与实战

     《Android开发入门与实战》内容上涵盖了用Android开发的大部分场景,从Android基础介绍、环境搭建、SDK介绍、Market使用,到应用剖析、组件介绍、实例演示等方面。从技术实现上,讲解了5个Android平台下的完整综合...

    安卓(android)经典开发教程15本全

    Android驱动开发入门及手机案例开发分析教程.pdf Android系统移植技术详解.doc Android新手开发教程.pdf Android应用程序开发36技.pdf Android应用开发详解.pdf Linux内核阅读心得体会.pdf linux Android基础知识...

    Android开发2019(很好很详细)ppt

    Android开发ppt,2019年辛苦整理的最新版,基本上是最新版也是最实用的。2019年春上课用的课件,使用过半,内容很全,效果很好。Android Studio的gradle使用的是3.0版的。唯一的缺憾就是没有介绍最新的Android框架,...

    Google Android开发入门与实战的代码

    Google Android开发入门与实战的代码 1章 掀起你的盖头来——初识Android. 1 1.1 认识Android 1 1.2 Android的背景 2 1.2.1 Android的历史 2 1.2.2 Android的发展 2 1.3 我的Android我做主 2 ...

    14本安卓android开发教程书籍源代码.rar

    14本安卓android开发教程书籍源代码让您从安卓开发新手到高手,快速具备独立开发经验,最全api教程大合集 安卓AndroidAPI教程 安卓android编译总结 安卓android开发从零开始代码若水 二维码生成图片 安卓中国象棋源码 ...

    Android 应用开发入门经典教程

    安卓的应用开发入门教程,总结的挺不错的,也挺容易接受

    android 开发入门指南

    如果想学好Android开发,这是一个快速入门的书,一天看两章的话,一个星期看完.再花一个星期总结。两个星期就差不多对Android有理解,应付一般的面试,绝对没有问题.

    16本android入门开发教程打包下载

    16本android入门开发教程打包...深入浅出Android——Android开发经典教材.pdf linux Android基础知识总结.pdf Android开发手册——API函数详解.pdf Android 开发环境搭建步骤详细图解.pdf 。。。。。 共16本!!!!

    Android入门到精通知识总结.pdf

    Android入门到精通知识总结,适合与Android知识的中初级学习者,个人Android开发实例及经验总结

    android开发资料大全

    新版Android开发教程及笔记-完整版 《Android中文教程》中文版 《android基础教程合集》 Android实例教程 会员贡献索引贴 实用Android开发工具和资源精选 APK权限大全 - Android必懂知识 最无私的Android资料...

    14本安卓开发书籍

    Android SDK 中文开发文档.pdf Android 开发环境搭建步骤...Android驱动开发入门及手机案例开发分析教程.pdf linux Android基础知识总结.pdf Linux内核阅读心得体会.pdf 深入浅出Android——Android开发经典教材.pdf

Global site tag (gtag.js) - Google Analytics