• Android开发框架


    总觉得不用框架直接开发比较繁琐,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;
        }
        
    }

    代码简洁了好多!

  • 相关阅读:
    rsyslog日志服务器搭建
    使用原生js实现对table中的某个单元格进行编辑并提交后台修改数据
    使用vuex管理的状态数据在刷新页面后数据丢失的问题
    brew install mongodb
    brew安装与启动redis
    zsh设置代理
    DNS Rebinding漏洞原理
    防数据泄露_MySQL库和数据安全
    PHP代码审计_用==与===的区别
    MySQL提权 通过UDF
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/4142131.html
Copyright © 2020-2023  润新知