Android学习记录之ListView和ScrollView区别
来源:互联网 发布:中云数据科技有限公司 编辑:程序博客网 时间:2024/04/29 18:47
ScrollView中不管有多少个数据项都会全部加载
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.同样用监视器看会有细微的变化
0 0
- Android学习记录之ListView和ScrollView区别
- Android学习之——ScrollView和ListView,GridView嵌套
- Android之ListView和ScrollView事件冲突
- android:scrollView学习记录
- Android 学习记录-ScrollView
- scrollview和listview的区别
- Android学习之——ScrollView和ListView,GridView嵌套,显示顶
- Android之ScrollView嵌套ListView
- Android之ScrollView嵌套ListView
- Android之ScrollView嵌套ListView
- Android学习之当ScrollView遭遇ListView(GridView)
- Android学习之解决ScrollView嵌套ListView显示的错误
- Android高级学习之RecylerView和ListView的区别
- (转)Android高级学习之RecylerView和ListView的区别
- android listview和scrollview共存
- android listview,GridView 和 ScrollView
- Android之ScrollView嵌套ListView和GridView冲突的解决方法
- Android学习记录-ListView
- final, finally, finalize
- mybatis中的#和$的区别
- 任务的批量提交invokeAll两种方法的区别
- 欢迎使用CSDN-markdown编辑器
- CI伪静态分页
- Android学习记录之ListView和ScrollView区别
- 新手写教程之——Unity环境搭建
- 有多少种方式可以在vim中插入递增的数字
- .NET与JSP页面之间消息通讯(跨域,使用html5的postMessage实现)
- 利用Proxy Cache使Nginx对静态资源进行缓存
- 下拉刷新ListView讲解,自定义PullToRefreshListView
- LeetCode 102 Binary Tree Level Order Traversal
- 数据结构实用概念
- linux shell script 练习