您的位置:首页 > 移动开发 > Android开发

 paip.android环境搭建与开发事例

2013-08-05 22:07 337 查看
 paip.android环境搭建与开发事例

 

好长时间没有玩AndROID了。。以前常常做ANDROID的,今天决定在下载一个要做个时间设置器

 

作者Attilax
,  EMAIL:1466519819@qq.com

来源:attilax的专栏
地址:http://blog.csdn.net/attilax
 

1.      
下载ECLIPSE+ADT+SDK

以前都是一个个单独下载,现在都可以集成在一起了。。

adt-bundle-windows-x86-20130729.ZIP 
(400M)

 

打开一看,晕,连C++都有了。。全面..

 

2.      
建立项目

NEW >ANDROID APPLICATION..

MINI S DK:默认2.2,,比较合理不用改

Target sdk:指明最高SDK版本。。默认4.3,为了兼容性,也改成2.2.

Complile withd: 默认4.3,无法改改。还好,这个不影响。最后生成的APK可以在2.2下运行。。

 

 

3.      
建立界面

拖拉个文本框,拖拉个按钮上去如下图

 

 

 

/atiapp2/res/layout/activity_main_activity1.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="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity1"
>
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
/>
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="104dp"
        android:text="Button"
/>
 
</RelativeLayout>

 

4.          
查看启动界面

/atiapp2/AndroidManifest.xml

要死有多个界面,可以指定启动界面

 

<?xml
version="1.0"
encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.atiapp2"
    android:versionCode="1"
    android:versionName="1.0"
>
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8"
/>
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
>
        <activity
            android:name="com.example.atiapp2.MainActivity1"
            android:label="@string/app_name"
>
            <intent-filter>
                <action
android:name="android.intent.action.MAIN"
/>
 
                <category
android:name="android.intent.category.LAUNCHER"
/>
            </intent-filter>
        </activity>
    </application>
 
</manifest>

 

 

 

 

 

5.  建立按键点击事件

 
  <Button
             android:id="@+id/button25"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignLeft="@+id/editText1"
             android:layout_below="@+id/editText1"
             android:layout_marginTop="28dp"
             android:text="Button"
             
               android:onClick="button1click" />
 
 
-----------MainActivity.java-------
publicvoid button1click(View view)
    {
       
    EditText  edt=(EditText)findViewById(R.id.editText1);
 
        String str="my name is attilax";
       
       edt.setText(str);
    }
 
其中,R.java是系统自动生成。。所有的多个界面控件ID都累积在那里
 

6.调试

调试前要建立个AVD虚拟设备..

再开始RUN AS>ANDROID APPLICATION

可以在CONSOLE下看到当前进展。。。模拟器启动比较慢,耐心等待。模拟器启动后不用关。。以后再次调试就很快。

 

[2013-08-05 22:18:52 - atiapp2] ------------------------------
[2013-08-05 22:18:52 - atiapp2] Android Launch!
[2013-08-05 22:18:52 - atiapp2] adb is running normally.
[2013-08-05 22:18:52 - atiapp2] Performing com.example.atiapp2.MainActivity1 activity launch
[2013-08-05 22:18:52 - atiapp2] Automatic Target Mode: launching new emulator with compatible AVD 'avd1'
[2013-08-05 22:18:52 - atiapp2] Launching a new emulator with Virtual Device 'avd1'
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] could not get wglGetExtensionsStringARB
[2013-08-05 22:19:00 - Emulator] Failed to create Context 0x3005
[2013-08-05 22:19:00 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2013-08-05 22:19:03 - atiapp2] New emulator found: emulator-5554
[2013-08-05 22:19:03 - atiapp2] Waiting for HOME ('android.process.acore') to be launched...
[2013-08-05 22:19:52 - atiapp2] HOME is up on device 'emulator-5554'
[2013-08-05 22:19:52 - atiapp2] Uploading atiapp2.apk onto device 'emulator-5554'
[2013-08-05 22:19:52 - atiapp2] Installing atiapp2.apk...
[2013-08-05 22:20:37 - atiapp2] Success!
[2013-08-05 22:20:37 - atiapp2] Starting activity com.example.atiapp2.MainActivity1 on device emulator-5554
[2013-08-05 22:20:39 - atiapp2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.atiapp2/.MainActivity1 }
[2013-08-05 22:20:39 - atiapp2] ActivityManager: Warning: Activity not started, its current task has been brought to the front

就OK了。。

 

模拟器启动后不用关。。以后再次调试就很快。

 

参考:

Android开发之旅:环境搭建及HelloWorld -
吴秦 - 博客园
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: