ButterKnife

  • 1.Introduction 简介 【黄油切刀】
    • 1)Annotate fields with @Bind and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout. 在定义视图元素前添加注释符号@Bind(ID) 注释框架会自动关联映射到相关联的布局文件中 ,运用在activity中

      Butterknife.bind(this) 必须声明在setContentView之后
      大致等价于:
    • 2)Instead of slow reflection, code is generated to perform the view look-ups. Calling bind delegates to this generated code that you can see and debug.绑定操作
    • 3)可以绑定关联映射各种定制视图View root, 比如在fragment中,利用方法Butterknife.bind(this,view);You can also perform binding on arbitrary objects by supplying your own view root.
    • 4)第三个使用场景:ViewHolder 分流适配器管理ltem的视图Another use is simplifying the view holder pattern inside of a list adapter.
    • 5)Bind arbitrary objects using an activity as the view root. If you use a pattern like MVC you can bind the controller using its activity with ButterKnife.bind(this, activity). 也是可以传入一个activity的
    • 6)Bind a view’s children into fields using ButterKnife.bind(this). If you use tags in a layout and inflate in a custom view constructor you can call this immediately after. Alternatively, custom view types inflated from XML can use it in the onFinishInflate() callback.
    • 7)使用场景四:多视图 apply方法 ,添加一个列表,成功和失败两种情况
    • 8)使用场景五:控件监听器映射绑定,Listeners can also automatically be configured onto methods.可以自己定义方法名和传入参数。
    • 9)使用场景六:在fragmnet中通常需要解除绑定,销毁视图后解除绑定,activity其实也有的Fragments have a different view lifecycle than activities. When binding a fragment in onCreateView, set the views to null in onDestroyView. Butter Knife has an unbind method to do this automatically.
    • 10)可选项,虽然这么说,但是还是建议在开发时加上,原因是因为@Nullable 是为了抑制因找不到目标组件而出现的异常,By default, both @Bind and listener bindings are required. An exception will be thrown if the target view cannot be found.To suppress this behavior and create an optional binding, add a @Nullable annotation to the field or method,Note: Any annotation named @Nullable can be used for this purpose. It is encouraged to use the @Nullable annotation from Android’s “support-annotations” library,
      参考:
      http://tools.android.com/tech-docs/support-annotations
    • 11)使用场景七:多个监听以及仿造findViewById 的Butterknife.findById()Method annotations whose corresponding listener has multiple callbacks can be used to bind to any one of them. Each annotation has a default callback that it binds to. Specify an alternate using the callback parameter.Also included are findById methods which simplify code that still has to find views on a View, Activity, or Dialog. It uses generics to infer the return type and automatically performs the cast.


      http://www.tuicool.com/articles/Q3mmay/
      http://blog.csdn.net/sbvfhp/article/details/47451835
      http://jakewharton.github.io/butterknife/
      http://jakewharton.github.io/butterknife/
      http://blog.csdn.net/bboyfeiyu/article/details/52572963
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值