Android ScrollView listview 自定义listview导致低配置手机卡死现象
2016-05-16 13:25
579 查看
项目中,有这样的需求,需要在listview外层再加一个scorllview以便将listview的布局在某个时候往上移动,一开始直接像下面的方式,只能显示一个item:
<ScrollView
android:id="@+id/price_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/price_quote_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@color/white" >
</ListView>
</ScrollView>
但运行之后看到的现象只显示了listview的一个item,这样肯定是不行的,百度了一下很多人采取的方式是重写listview的onmeasure方法,如下:
<ScrollView
android:id="@+id/price_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/price_quote_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@color/white" >
</ListView>
</ScrollView>
但运行之后看到的现象只显示了listview的一个item,这样肯定是不行的,百度了一下很多人采取的方式是重写listview的onmeasure方法,如下:
package allone.verbank.apad.client.component.fixedListView; import android.content.Context; import android.util.AttributeSet; import android.widget.ListView; public class PriceListViewScroll extends ListView { public PriceListViewScroll(Context context) { super(context); } public PriceListViewScroll(Context context, AttributeSet attrs) { super(context, attrs); } public PriceListViewScroll(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }的确使用lisview的只显示一行的问题,但重新打开项目,运行的时候,在三星的平板上整个界面还算不卡,listview略卡,但一旦给测试人员测试的时候发现,使用LG或者低配置的手机运行平板的程序时,就会出现卡死的状况,将自定义的listview的去掉就恢复正常了,我的理解是使用上述的自定义的listview,进行绘制的时候,由于每次更新服务器的大量数据时,需要重新计算高度和宽度,挺耗内存,所以导致低配置的手机卡死了,有前辈如果知道的,麻烦告诉我一下,参考链接如下:http://blog.csdn.net/qinjuning/article/details/8074262
相关文章推荐
- 使用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