Android開發架構

來源:互聯網
上載者:User

標籤:

總覺得不用架構直接開發比較繁瑣,java下有很多,我使用ssh,php下有很多,我使用ThinkPHP,Delphi下還沒有找到一個比較合適的,Android下呢?今天在網上搜尋了一下,發現也是有很多不錯的架構的,比較了一下,發現兩個比較好用的:Afinal和xUtils。

Afinal:

http://github.com/yangfuhai/afinal

xUtils:

https://github.com/wyouflf/xUtils

xUtils是在Afinal上fork了一個分支。

這兩個架構都使用了註解方式,使用起來真的很方便:

  • 完全註解方式就可以進行UI綁定和事件綁定

  • 無需findViewById和setClickListener等

簡單的入門介紹:

Afinal:

http://www.oschina.net/p/afinal/

xUtils源起:

http://my.oschina.net/u/1171837/blog/147544

對架構感興趣的朋友可以試一下。

也感謝作者提供的好工具!

 

附上簡單的控制項和事件注入樣本:

 

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=".MainActivity" >    <TextView        android:id="@+id/tvHello"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" />    <Button        android:id="@+id/btnHello"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="68dp"        android:layout_toRightOf="@+id/tvHello"        android:text="Button" /></RelativeLayout>

 

java:

package com.example.myxutils;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.TextView;import com.lidroid.xutils.ViewUtils;import com.lidroid.xutils.view.annotation.ViewInject;import com.lidroid.xutils.view.annotation.event.OnClick;public class MainActivity extends Activity {    // xUtils的view註解要求必須提供id,以使代碼混淆不受影響。    @ViewInject(R.id.tvHello)TextView tvHello;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);              //在Activity中注入:        ViewUtils.inject(this); //注入view和事件        tvHello.setText("Hello,Garfield !");    }            @OnClick(R.id.btnHello)    public void testButtonClick(View v) { // 方法簽名必須和介面中的要求一致        tvHello.setText("這是按鈕事件 !");    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }    }

代碼簡潔了好多!

Android開發架構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.