北京网站seo技术厂家,院系网站建设具体要求,wordpress页面标签页,织梦后台网站栏目空白直接继承自 AbsListView#xff0c;AbsListView 继承自 AdapterView#xff0c;AdapterView 又继承自 ViewGroup。
Adpater 在 ListView 和数据源之间起到了一个桥梁的作用
RecycleBin 机制
RecycleBin 机制是ListView能够实现成百上千条数据都不会OOM最重要的一个原因。R…
直接继承自 AbsListViewAbsListView 继承自 AdapterViewAdapterView 又继承自 ViewGroup。
Adpater 在 ListView 和数据源之间起到了一个桥梁的作用
RecycleBin 机制
RecycleBin 机制是ListView能够实现成百上千条数据都不会OOM最重要的一个原因。RecycleBin是AbsListView的一个内部类。
RecycleBin当中使用mActiveViews这个数组来存储View调用这个方法后就会根据传入的参数来将ListView中的指定元素存储到mActiveViews中。mActiveViews当中所存储的View一旦被获取了之后就会从mActiveViews当中移除下次获取同样位置的时候将会返回null所以mActiveViews不能被重复利用。addScrapView()用于将一个废弃的View进行缓存该方法接收一个View参数当有某个View确定要废弃掉的时候比如滚动出了屏幕就应该调用这个方法来对View进行缓存RecycleBin当中使用mScrapViews和mCurrentScrap这两个List来存储废弃View。getScrapView 用于从废弃缓存中取出一个View这些废弃缓存中的View是没有顺序可言的因此getScrapView()方法中的算法也非常简单就是直接从mCurrentScrap当中获取尾部的一个scrap view进行返回。我们都知道Adapter当中可以重写一个getViewTypeCount()来表示ListView中有几种类型的数据项而setViewTypeCount()方法的作用就是为每种类型的数据项都单独启用一个RecycleBin缓存机制。
View的流程分三步onMeasure()用于测量View的大小onLayout()用于确定View的布局onDraw()用于将View绘制到界面上。
常用属性 隐藏滑动条 设置android:scrollbarsnone 或者 setVerticalScrollBarEnabled(true); 设置点击颜色 通过这个 cacheColorHint 将颜色设置为透明 :#00000000 底部开始显示 将 stackFromBottom 属性设置为 true
简单实例
1. 效果图
2. 实体类
public class Animal {private String aName;private String aSpeak;private int aIcon;public Animal() {}public Animal(String aName, String aSpeak, int aIcon) {this.aName aName;this.aSpeak aSpeak;this.aIcon aIcon;}public String getaName() {return aName;}public String getaSpeak() {return aSpeak;}public int getaIcon() {return aIcon;}public void setaName(String aName) {this.aName aName;}public void setaSpeak(String aSpeak) {this.aSpeak aSpeak;}public void setaIcon(int aIcon) {this.aIcon aIcon;}
}3. 适配器 public class AnimalAdapter extends BaseAdapter {private LinkedListAnimal mData;private Context mContext;public AnimalAdapter(LinkedListAnimal mData, Context mContext) {this.mData mData;this.mContext mContext;}Overridepublic int getCount() {return mData.size();}Overridepublic Object getItem(int position) {return null;}Overridepublic long getItemId(int position) {return position;}Overridepublic View getView(int position, View convertView, ViewGroup parent) {convertView LayoutInflater.from(mContext).inflate(R.layout.item_list_animal,parent,false);ImageView img_icon (ImageView) convertView.findViewById(R.id.img_icon);TextView txt_aName (TextView) convertView.findViewById(R.id.txt_aName);TextView txt_aSpeak (TextView) convertView.findViewById(R.id.txt_aSpeak);img_icon.setBackgroundResource(mData.get(position).getaIcon());txt_aName.setText(mData.get(position).getaName());txt_aSpeak.setText(mData.get(position).getaSpeak());return convertView;}
}4. MainActivity.java
public class MainActivity extends AppCompatActivity {private ListAnimal mData null;private Context mContext;private AnimalAdapter mAdapter null;private ListView list_animal;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mContext MainActivity.this;list_animal (ListView) findViewById(R.id.list_animal);mData new LinkedListAnimal();mData.add(new Animal(狗说, 你是狗么?, R.mipmap.ic_icon_dog));mData.add(new Animal(牛说, 你是牛么?, R.mipmap.ic_icon_cow));mData.add(new Animal(鸭说, 你是鸭么?, R.mipmap.ic_icon_duck));mData.add(new Animal(鱼说, 你是鱼么?, R.mipmap.ic_icon_fish));mData.add(new Animal(马说, 你是马么?, R.mipmap.ic_icon_horse));mAdapter new AnimalAdapter((LinkedListAnimal) mData, mContext);list_animal.setAdapter(mAdapter);}}
文章转载自: http://www.morning.wdply.cn.gov.cn.wdply.cn http://www.morning.kcsx.cn.gov.cn.kcsx.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn http://www.morning.kgnrh.cn.gov.cn.kgnrh.cn http://www.morning.xrrjb.cn.gov.cn.xrrjb.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.fxqjz.cn.gov.cn.fxqjz.cn http://www.morning.xrct.cn.gov.cn.xrct.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.skbbt.cn.gov.cn.skbbt.cn http://www.morning.rysmn.cn.gov.cn.rysmn.cn http://www.morning.xrwbc.cn.gov.cn.xrwbc.cn http://www.morning.tzmjc.cn.gov.cn.tzmjc.cn http://www.morning.kstlm.cn.gov.cn.kstlm.cn http://www.morning.clpkp.cn.gov.cn.clpkp.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.nqlcj.cn.gov.cn.nqlcj.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn http://www.morning.fktlr.cn.gov.cn.fktlr.cn http://www.morning.yrkdq.cn.gov.cn.yrkdq.cn http://www.morning.chtnr.cn.gov.cn.chtnr.cn http://www.morning.tpps.cn.gov.cn.tpps.cn http://www.morning.mgwdp.cn.gov.cn.mgwdp.cn http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn http://www.morning.kcxtz.cn.gov.cn.kcxtz.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.dpgdj.cn.gov.cn.dpgdj.cn http://www.morning.rkqzx.cn.gov.cn.rkqzx.cn http://www.morning.wfykn.cn.gov.cn.wfykn.cn http://www.morning.bklhx.cn.gov.cn.bklhx.cn http://www.morning.wnxqf.cn.gov.cn.wnxqf.cn http://www.morning.bzjpn.cn.gov.cn.bzjpn.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.fxqjz.cn.gov.cn.fxqjz.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.kmlmf.cn.gov.cn.kmlmf.cn http://www.morning.rnqbn.cn.gov.cn.rnqbn.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.lgwjh.cn.gov.cn.lgwjh.cn http://www.morning.dlmqn.cn.gov.cn.dlmqn.cn http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn http://www.morning.smcfk.cn.gov.cn.smcfk.cn http://www.morning.lxyyp.cn.gov.cn.lxyyp.cn http://www.morning.mprky.cn.gov.cn.mprky.cn http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.shawls.com.cn.gov.cn.shawls.com.cn http://www.morning.dnycx.cn.gov.cn.dnycx.cn http://www.morning.xnlj.cn.gov.cn.xnlj.cn http://www.morning.nbmyg.cn.gov.cn.nbmyg.cn http://www.morning.nzfyx.cn.gov.cn.nzfyx.cn http://www.morning.kgtyj.cn.gov.cn.kgtyj.cn http://www.morning.trrhj.cn.gov.cn.trrhj.cn http://www.morning.ppqzb.cn.gov.cn.ppqzb.cn http://www.morning.bkqw.cn.gov.cn.bkqw.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.nmngg.cn.gov.cn.nmngg.cn http://www.morning.ksjmt.cn.gov.cn.ksjmt.cn http://www.morning.mlckd.cn.gov.cn.mlckd.cn http://www.morning.npmx.cn.gov.cn.npmx.cn http://www.morning.ndcjq.cn.gov.cn.ndcjq.cn http://www.morning.rxdsq.cn.gov.cn.rxdsq.cn http://www.morning.mhwtq.cn.gov.cn.mhwtq.cn http://www.morning.yfzld.cn.gov.cn.yfzld.cn http://www.morning.bflwj.cn.gov.cn.bflwj.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.gskzy.cn.gov.cn.gskzy.cn http://www.morning.tmfhx.cn.gov.cn.tmfhx.cn http://www.morning.bzkgn.cn.gov.cn.bzkgn.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.pzjfz.cn.gov.cn.pzjfz.cn http://www.morning.mooncore.cn.gov.cn.mooncore.cn http://www.morning.fygbq.cn.gov.cn.fygbq.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.xlmgq.cn.gov.cn.xlmgq.cn http://www.morning.gcfrt.cn.gov.cn.gcfrt.cn