zoukankan      html  css  js  c++  java
  • listview前几个item怎么不停加载

    在加载前几个item的时候,listview有个Adapter,里面的getView方法会被调用好几遍。原因可能有两种:

    1.listview在布局文件里高度写成了wrap_content

    <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/ll_root"
         android:orientation="vertical" >
    
    <!--  <ImageView
         android:id="@+id/iv_image"
         android:layout_width="match_parent"
         android:layout_height="180dp" 
         android:scaleType="fitXY"/> -->
    
         <ListView
             android:id="@+id/lv_list"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" >
    
    </ListView>
     
     </LinearLayout>

    由于app不知道你这个listview要用多少个item才能撑满全屏,所以它就不停地试,直到满为止。

    2.布局文件里没有listview,而是在代码里new出来listview,而且没有指定listview的高度是match_parent

            LinearLayout llRoot = (LinearLayout) findViewById(R.id.ll_root);
            ListView lv = new ListView(this);
            llRoot.addView(lv);
            lv.setAdapter(new BaseAdapter() { 
                                   。        
                                   。
                                   。

     原因跟第一种情况的原因是一样的

  • 相关阅读:
    CVS,GIT,Mercurial和SVN比较
    ubuntu-使用终端配置网络
    编写简单的hashCode方法
    编写高质量equals方法
    文件上传和下载
    Java常用命令
    增删查改-MySQL
    Newton迭代法-C++
    二分法-C++
    适配器模式
  • 原文地址:https://www.cnblogs.com/johnsonwei/p/5935452.html
Copyright © 2011-2022 走看看