简略试用Android Annotations

简单试用Android Annotations

参考:试用android annotations

 

       Android Annotations号称 "是一个能够加速 Android 开发的开源框架,它可以帮助开发者处理

一些前后台任务、rest 服务、应用类、代码片段等,让开发者专注于真正重要的东西”。

 

      为了看看实际效果,今天搭建环境,简单试用了一下(只是跑起来了。。。)

 

一、准备工作

  1. https://github.com/excilys/androidannotations下载源码及相关的jar包
  2. 按照https://github.com/excilys/androidannotations/wiki/Eclipse-Project-Configuration上的步骤配置Eclipse

二、运行Demo

       将demo中examples\HelloWorldEclipse目录下的项目导入到Eclipse中,运行良好

 

三、运行简单工程

  1. 工程目录

    简略试用Android Annotations
     
  2. 配置Eclipse
    简略试用Android Annotations
     
    简略试用Android Annotations

  3. 代码

    Java代码 简略试用Android Annotations 简略试用Android Annotations简略试用Android Annotations
    1. package com.example.tmptmp;  
    2.   
    3. import com.googlecode.androidannotations.annotations.EActivity;  
    4.   
    5. import android.app.Activity;  
    6.   
    7. @EActivity(R.layout.activity_first)  
    8. public class FirstActivity extends Activity {  
    9.   
    10. }  
    package com.example.tmptmp;
    
    import com.googlecode.androidannotations.annotations.EActivity;
    
    import android.app.Activity;
    
    @EActivity(R.layout.activity_first)
    public class FirstActivity extends Activity {
    
    }
    
     
    Xml代码 简略试用Android Annotations 简略试用Android Annotations简略试用Android Annotations
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent" >  
    5.   
    6.     <TextView  
    7.         android:id="@+id/helloTextView"  
    8.         android:layout_width="wrap_content"  
    9.         android:layout_height="wrap_content"  
    10.         android:layout_alignParentLeft="true"  
    11.         android:layout_alignParentTop="true"  
    12.         android:layout_marginLeft="17dp"  
    13.         android:layout_marginTop="15dp"  
    14.         android:text="TextView" />  
    15.   
    16. </RelativeLayout>  
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@+id/helloTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="17dp"
            android:layout_marginTop="15dp"
            android:text="TextView" />
    
    </RelativeLayout>
    
     
    Xml代码 简略试用Android Annotations 简略试用Android Annotations简略试用Android Annotations
    1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     package="com.example.tmptmp"  
    3.     android:versionCode="1"  
    4.     android:versionName="1.0" >  
    5.   
    6.     <uses-sdk  
    7.         android:minSdkVersion="8"  
    8.         android:targetSdkVersion="17" />  
    9.   
    10.     <application  
    11.         android:allowBackup="true"  
    12.         android:icon="@drawable/ic_launcher"  
    13.         android:label="@string/app_name"  
    14.         android:theme="@style/AppTheme" >  
    15.         <activity android:name="com.example.tmptmp.FirstActivity_" >  
    16.             <intent-filter>  
    17.                 <action android:name="android.intent.action.MAIN" />  
    18.   
    19.                 <category android:name="android.intent.category.LAUNCHER" />  
    20.             </intent-filter>  
    21.         </activity>  
    22.     </application>  
    23.   
    24. </manifest>  
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.tmptmp"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity android:name="com.example.tmptmp.FirstActivity_" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
     
  4. 运行结果

    可以正常运行