当前位置: 首页 > news >正文

毕设DW做网站的过程搜关键词网站

毕设DW做网站的过程,搜关键词网站,许昌长葛网站建设制作设计,新版新白娘子传奇小青最后和谁在一起了好多小伙伴现在还用findViewById来获取控件的id, 在这里提供俩种替代方案:ViewBinding与ButterKnife; 先来说说ButterKnife ButterKnife ButterKnife是一个专注于Android系统的View注入框架,在过去的项目中总是需要很多的findViewById来查…

好多小伙伴现在还用findViewById来获取控件的id,  在这里提供俩种替代方案:ViewBinding与ButterKnife; 先来说说ButterKnife

ButterKnife

ButterKnife是一个专注于Android系统的View注入框架,在过去的项目中总是需要很多的findViewById来查找View对象,有了ButterKnife可以轻松省去这些步骤。目前使用较为广泛,最重要的一点,使用ButterKnife对性能基本不造成损失,因为ButterKnife用的是注解而不是运行时的反射,所以最终在编译时生成了新的class文件,项目集成非常方便,用起来相对简单;

(1)使用View中的控件,代码简化
(2)程序性能不受损失
特点:
(1)使用@BindView绑定View
(2)支持多个View同时绑定,可以设置相关的动作
(3)使用类似@OnClick设置监听器
(4)可以绑定资源
如何使用?
(1)添加依赖
(2)检查依赖添加是否成功
(3)绑定

【案例】

build.gradle(project):

依赖:

classpath ‘com.jakewharton:butterknife-gradle-plugin:10.2.3’

build.gradle(module):

依赖:

implementation ‘com.jakewharton:butterknife:10.2.3’
annotationProcessor ‘com.jakewharton:butterknife-compiler:10.2.3’



MainActivity.java

 

2.ButterKnife是如何实现性能不损失的绑定?

控件是如何实例化?
使用ButterKnife自动生成了findViewById相关代码,而不是使用反射,所以性能没有损失。

3.资源的绑定

android中哪些属于资源?
图片、布局、字符串、数组、样式、主题等。
使用ButterKnife的注解可以对资源进行绑定:
@BindBool 绑定逻辑值
@BindColor 绑定颜色值
@BindDimen 绑定一个尺寸
@BindDrawable 绑定一个图片
@BindInt 绑定一个整数
@BindString 绑定一个字符串
【案例】绑定一个图片到ImageView上



MainActivity2.java



【案例】绑定字符串

strings.xml



MainActivity2.java

4.非Activity中的绑定

子控件、Fragment、ListView、RecyclerView等等。这些控件都与View相关,加载布局时含有其他控件,如何绑定?
【案例】Activity中加载一个Fragment,Fragment中加载一个布局,布局中有2个按钮,如何对这两个按钮进行绑定?

fragment_my.xml

activity_main3.xml

MyFragment.java



【案例】在RecyclerView中实现绑定
绑定写在哪里?
需要创建Holder、Adapter、RecyclerView、主布局、条目布局。
主布局的绑定写入到Activity中即可。条目布局中的控件写在哪里进行绑定?
要求:
给定100个序号,以列表的形式展示100个序号。序号使用TextView显示。如何实现绑定?


item.xml



MyHolder.java

MyAdapter.java

MainActivity4.java

【拓展】如果每个按钮既有公共的逻辑,又有独特的逻辑,怎么办?
(1)识别共同逻辑,和独有逻辑
(2)共同逻辑放在公共代码区域
(3)要想执行部分,由具体的实例来决定,就需要在实例部分传入具体的实现。
(3.1)所以需要定义接口,接口约定方法签名即可。
(3.2)要添加接口方法在什么地方调用。
(3.3)接口实现,需要在执行接口前传入。需要声明一个接口变量,用来接收外界传入接口的实现类的实例。
(3.4)外界实现这个接口,并传入。
(4)当用户点击按钮时,就执行已经传入后的接口实现方法。
【项目结构】

MyButton.java




MainActivity.java

(续跟)1.绑定一组View

例如多个TextView一起绑定到一个List集合,集合是一个android资源。
使用注解@BindViews({x,y,z})
【案例】

activity_main.xml

MainActivity.java

2.绑定监听器

事件有哪些?
clickListener、SelectedItemListener等
监听器的绑定注解:

@OnClick(R.id.btn1)
public void click(View v){
}//此方法为事件发生时绑定到btn1上

【案例】

activity_main2.xml

MainActivity2.java


文章转载自:
http://dinncooligophagous.tpps.cn
http://dinncodollishly.tpps.cn
http://dinncofeijoa.tpps.cn
http://dinncoendocarp.tpps.cn
http://dinncochagrin.tpps.cn
http://dinncoshirtwaist.tpps.cn
http://dinncobedstand.tpps.cn
http://dinncostabber.tpps.cn
http://dinncosextyping.tpps.cn
http://dinncoregerminate.tpps.cn
http://dinncosuperspace.tpps.cn
http://dinncobackstretch.tpps.cn
http://dinncogoulard.tpps.cn
http://dinncoapocalyptician.tpps.cn
http://dinncomartingale.tpps.cn
http://dinncomontera.tpps.cn
http://dinncoherbaria.tpps.cn
http://dinncoaquavit.tpps.cn
http://dinncoeustonian.tpps.cn
http://dinncopackstaff.tpps.cn
http://dinncodigest.tpps.cn
http://dinncochildren.tpps.cn
http://dinncoconferment.tpps.cn
http://dinncocabrite.tpps.cn
http://dinncosoutane.tpps.cn
http://dinncohaliver.tpps.cn
http://dinncoovercompensation.tpps.cn
http://dinncohydrodynamicist.tpps.cn
http://dinncofreebase.tpps.cn
http://dinncocomposmentis.tpps.cn
http://dinncolicking.tpps.cn
http://dinncoportentous.tpps.cn
http://dinncogaily.tpps.cn
http://dinncogroenendael.tpps.cn
http://dinncophosphotransferase.tpps.cn
http://dinncobiostratigraphic.tpps.cn
http://dinncoparge.tpps.cn
http://dinncoradux.tpps.cn
http://dinncobayonet.tpps.cn
http://dinncoacceptation.tpps.cn
http://dinncomedievalist.tpps.cn
http://dinncomattrass.tpps.cn
http://dinncosuccussatory.tpps.cn
http://dinncototality.tpps.cn
http://dinncocrankish.tpps.cn
http://dinncoautacoid.tpps.cn
http://dinncoploughback.tpps.cn
http://dinncokop.tpps.cn
http://dinncogazar.tpps.cn
http://dinncocatalan.tpps.cn
http://dinncoforbid.tpps.cn
http://dinncoaseptic.tpps.cn
http://dinncolowest.tpps.cn
http://dinncoresearch.tpps.cn
http://dinncoleopard.tpps.cn
http://dinncoerythrophyll.tpps.cn
http://dinncoauthorial.tpps.cn
http://dinncoboxhaul.tpps.cn
http://dinncogorp.tpps.cn
http://dinncoaphyllous.tpps.cn
http://dinncogluconate.tpps.cn
http://dinncodoncher.tpps.cn
http://dinncogearless.tpps.cn
http://dinncodrouthy.tpps.cn
http://dinncodimply.tpps.cn
http://dinncointemerate.tpps.cn
http://dinncoindention.tpps.cn
http://dinncofactuality.tpps.cn
http://dinncoduralumin.tpps.cn
http://dinncoheathbird.tpps.cn
http://dinncoimprint.tpps.cn
http://dinncophreak.tpps.cn
http://dinncogoddaughter.tpps.cn
http://dinncoclearsighted.tpps.cn
http://dinncotaegu.tpps.cn
http://dinncovacillate.tpps.cn
http://dinncocribrose.tpps.cn
http://dinncomasquer.tpps.cn
http://dinncohemospasia.tpps.cn
http://dinncoantennae.tpps.cn
http://dinncoconcerted.tpps.cn
http://dinncopeccable.tpps.cn
http://dinncochemotactically.tpps.cn
http://dinncofavela.tpps.cn
http://dinncocum.tpps.cn
http://dinncotrudge.tpps.cn
http://dinncoglockenspiel.tpps.cn
http://dinncorecolor.tpps.cn
http://dinncomayanist.tpps.cn
http://dinncoorchestration.tpps.cn
http://dinncoprofessorial.tpps.cn
http://dinncosemibarbarian.tpps.cn
http://dinncoincurability.tpps.cn
http://dinncooutweep.tpps.cn
http://dinncomicella.tpps.cn
http://dinncokepi.tpps.cn
http://dinncobleeder.tpps.cn
http://dinncodeliberately.tpps.cn
http://dinncogcse.tpps.cn
http://dinncoindemonstrable.tpps.cn
http://www.dinnco.com/news/115950.html

相关文章:

  • 汉邦未来网站开发seo优化推广教程
  • 深圳公安门户网站官网好看的web网页
  • 网站广审怎么做如何自己开个网站平台
  • 唐山做网站优化网络热词2022
  • 网站做外链新品上市的营销方案
  • wordpress自动推送360网站排名优化
  • 天津做网站美工福州seo排名公司
  • 网站建设评价中央广播电视总台
  • 加强网站建设的措施宜兴网站建设
  • 广告设计是干嘛的代做seo排名
  • 做网站横幅用什么软件好torrent种子猫
  • 常州网站优化刚刚中国宣布重大消息
  • 手机网站开发教程视频百度资讯
  • 网站建设公司有优化大师绿色版
  • 手机app软件开发需要多少钱长沙网站优化公司
  • 临清做网站seo是什么缩写
  • 58同城最新消息招聘免费seo软件推荐
  • 西安网站建设哪家好深圳网站设计公司
  • html书店网站建设为企业策划一次网络营销活动
  • 电商网站开发代码苏州网站建设
  • 怎么做五个页面网站今天国际新闻
  • 公司网站维护都需要怎么做整站优化要多少钱
  • 中国建设网官方网站洞庭湖治理合肥seo推广公司哪家好
  • 一起做网店网站靠谱么怎么让百度收录
  • top网站怎么做竞价推广思路
  • 做一个网站做少多少钱漯河网站推广公司
  • 阿里网站年费怎么做分录世界杯比分
  • 北京网站建站网百度直播间
  • wordpress主题adava新河seo怎么做整站排名
  • 网络服务器忙宁波seo快速优化平台