大杀器-RoboBinding
来源:互联网 发布:怎么避免mac涂层脱落 编辑:程序博客网 时间:2024/05/21 04:24
介绍
一个实现了
数据绑定
Presentation Model(MVVM)
模式的Android开源框架。 在没有性能损失的前提下(使用源代码生成来替代Java反射),RoboBinding 帮助你编写更可读,易于测试与维护的UI代码。
- 通过绑定移除大量不必要的代码(如addXXListener(),findViewById()等) 。
- 将难于测试的Android代码以及运行过久且不切实际的Android单元测试 变为 pojo PresentationModels 及其普通的JUnit单元测试。
- 提供对象类型Cursor来替换 - 关系类型Cursor,因为我们已经习惯于操作对象 。
- 可以很容易的为任何自定义组件,第三方组件或Android widget编写属性绑定实现,简化代码,使项目易于维护。
官网: http://robobinding.org
有中文翻译版本,关于详细介绍,移步官网,下面主要填一下使用Android Studio配置时的一些坑.
根据官方介绍,我使用了AspectJ
(AS上不好配置),也可以不用
1.配置 app/build.gradle
buildscript{ repositories{ mavenCentral() maven(){ name 'RoboBinding AspectJPlugin Maven Repository' url "https://github.com/RoboBinding/RoboBinding-aspectj-plugin/raw/master/mavenRepo" } } dependencies { classpath 'com.android.tools.build:gradle:1.+' classpath 'org.robobinding:aspectj-plugin:0.8.4' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+' }}
注意需要引用v4,我是在libs添加的jar包
apply plugin: 'com.android.application'apply plugin: 'com.neenbedankt.android-apt'apply plugin: 'org.robobinding.android-aspectj'
compile ("org.robobinding:robobinding:0.8.9:with-aop-and-dependencies") { exclude group: 'com.google.guava', module: 'guava' } aspectPath ("org.robobinding:robobinding:0.8.9:with-aop-and-dependencies") { exclude group: 'com.google.guava', module: 'guava' } apt "org.robobinding:codegen:0.8.9" androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
repositories { jcenter() mavenCentral() maven() { name 'SonaType snapshot repository' url 'https://oss.sonatype.org/content/repositories/snapshots' }}
android { .... //这里是禁止xml中使用bind命名空间时报错的 lintOptions { disable 'UnusedAttribute', 'ValidFragment', 'GradleDependency', 'OnClick', 'MissingPrefix', 'MenuTitle' } ...}
以上片段是需要注意的
还有就是网络问题,在公司的网络Gradle死活都编译不通,回到家立马就好了
接下来就是使用了
以在Fragment中使用为例(官方的例子用法很全了)
1. fragment_demo.xml
<LinearLayout //加上命名空间 xmlns:bind="http://robobinding.org/android"<TextView bind:text="{content}"
点击事件 bind:onClick=”methodName”
还支持其他更多属性的绑定
- DemoPresentationModel.java
//加上注解@PresentationModelpublic class DemoPresentationModel{ private String content; //对应xml中bind:text="{content}" public String getContent(){ return content; } public String setContent(Content content){ this.content = content; }}
- DemoFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); presentationModel = new DemoPresentationModel(); presentationModel.setContent("内容"); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewBinder viewBinder = new BinderFactoryBuilder().build().createViewBinder(getActivity()); View rootView = viewBinder.inflateAndBind(R.layout.fragment_demo, presentationModel); //xml里面按照上面的要求,不能写错 return rootView; }
需要更新属性的,让POJO类实现HasPresentationModelChangeSupport
//加上注解@PresentationModelpublic class DemoPresentationModel implements HasPresentationModelChangeSupport{ private String content; //对应xml中bind:text="{content}" private PresentationModelChangeSupport changeSupport; public DemoPresentationModel(){ changeSupport = new PresentationModelChangeSupport(this); } public String getContent(){ return content; } public String setContent(Content content){ this.content = content; } public void updataContent(String newContent){ changeSupport.firePropertyChange("content");//更新content属性 }}
然后我们调用 updataContent
来更新视图
一下子简化好多代码和逻辑,还有其他更强大的功能,官网观看,还有中文的视频
0 0
- 大杀器-RoboBinding
- [源码]RoboBinding及思考
- Android MVVM框架RoboBinding初探
- RoboBinding(MVVM)框架介绍
- RoboBinding探究三:网络请求实现
- Android数据绑定组件RoboBinding使用详解
- Android MVP MVVM Presentation Model模式与基于RoboBinding应用
- MvvM----Robobinding的使用(1)环境搭建
- MvvM----Robobinding的使用(1)环境搭建
- RoboBinding探究一:TextView及EditText基础实现
- RoboBinding探究二:ImageView及自定义控件实现
- RoboBinding学习二:ImageView及自定义控件实现
- 实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架——RoboBinding
- RoboBinding:一个实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架
- 终极大杀器
- 最喜欢此等大杀器
- Android 滑动大杀器 ViewDragHelper
- 大杀器xgboost指南
- 基于Ubuntu网关配置(2)-- DHCP
- 24岁的自我审视
- 定时任务完成日志切割
- js-refferrer无法显示前个页面的地址的解决方法
- 正确理解MySQL中列索引和多列索引
- 大杀器-RoboBinding
- Java-----11、JDBC编程
- scv.lua 的使用
- echart使用例子
- 测试题--by 罗雨屏
- Android-LinearGradient实现TextView字体渐变的效果
- windows 路由表
- 设计模式读书笔记-----访问者模式
- hibernate+spring架构有感