Android学习记录之ListView和ScrollView区别
2016-04-08 18:17
501 查看
ScrollView中不管有多少个数据项都会全部加载
MainActivity.java
scrolllist.xml
listitem.xml
1.用Android Studio中的Memory监视器可以看出不管怎么滑动都不会变化
ListView
MainActivity.java
listview.xml
listitem.xml
1.同样用监视器看会有细微的变化
MainActivity.java
package com.example.android.listviewandscrollview; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.scrolllist); LayoutInflater mflater = LayoutInflater.from(this); LinearLayout scroll = (LinearLayout)findViewById(R.id.scrollLayout); for(int i =0 ;i<120;i++){ View infoView = mflater.inflate(R.layout.listitem, null); scroll.addView(infoView); } } }
scrolllist.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:id="@+id/scrollList" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:id="@+id/scrollLayout" android:layout_width="match_parent" android:layout_height="match_parent"> </LinearLayout> </ScrollView> </LinearLayout>
listitem.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <TextView android:id="@+id/textView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Tom"/> </LinearLayout>
1.用Android Studio中的Memory监视器可以看出不管怎么滑动都不会变化
ListView
MainActivity.java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listview); ListView listView = (ListView)findViewById(R.id.listView); ListAdapter listAdapter = new SimpleAdapter(this, getData(), R.layout.listitem , new String[]{"image", "text"}, new int[]{R.id.imageView, R.id.textView}); listView.setAdapter(listAdapter); } private List<Map<String, Object>> getData(){ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); for(int i=0; i<120; i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("image", R.mipmap.ic_launcher); map.put("text", "Tom"); list.add(map); } return list; } }
listview.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
listitem.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/textView" android:layout_height="wrap_content" android:layout_width="wrap_content"/> </LinearLayout>
1.同样用监视器看会有细微的变化
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories