listview最后有空行

时间:2014-10-14 09:10:56

标签: android listview

我的应用程序中有一个listview,但我的问题是ListView在最后一项下面有一个空行,就像这张图片一样。

link:http://blog.naver.com/wolfjunghun/220150613193

例如,listview的大小为20,但listview有21行。

我怎样摆脱那条线(不仅使用android:footerDividersEnabled =" false",而且还有空格)和空白空间......? 拜托,有人帮帮我!

下面的.xml文件

           <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginTop="20dp"
                    android:layout_marginBottom="20dp"
                    >
                <ListView
                       android:id="@+id/list_comment"
                       android:layout_width="fill_parent"
                       android:layout_height="wrap_content"
                       android:scrollbars="none"
                       android:divider="@drawable/comment_divider"
                       android:overScrollMode="never"
                       android:footerDividersEnabled="false"
                       android:fadingEdgeLength="0dp"
                       />

                <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_marginBottom="50dp"  
                    />

           </LinearLayout>

并在activity中调用xml:

if(mCellEntity.getComments()!=null&&mCellEntity.getComments().size()>0){
        list_comment.setVisibility(View.VISIBLE);
        findViewById(R.id.frame_cell).setBackgroundColor(Color.parseColor("#ebedee"));

        Collections.sort(mCellEntity.getComments(), new TimeAscCompare());

        commentAdapter=new CommentAdapter(this, R.layout.cell_comment_item2, mCellEntity.getComments());
        list_comment.setAdapter(commentAdapter);
        DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
        int width = displayMetrics.widthPixels;
        int margin = (int) ComUtil.convertDpToPixel(40,this);
        width = width -margin; 
        ListViewHelper.getListViewSize(list_comment, width);

    }else{
        list_comment.setVisibility(View.GONE);
    }
Commentadapter中的getView方法:

public class CommentAdapter extends BaseAdapter {

........... skip ..........

public CommentAdapter(Activity ctx, int layout , ArrayList<CellEntity> timeLineList){
     inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     this.list = timeLineList;
     this.ctx = ctx;
     this.layout = layout;
     this.applicationClass = (ApplicationClass)ctx.getApplicationContext();

     SharedPreferences userPref = ctx.getSharedPreferences(CommonConst.PREFS_USER_INFO, Activity.MODE_PRIVATE);
     mobileView = userPref.getBoolean(CommonConst.UserInfo.PREFS_MOBILE_VIEW, false);


       if (this.mTypeface == null)
           this.mTypeface = Typeface.createFromAsset(ctx.getAssets(), "NanumGothicBold.ttf.mp3");


       if(ctx instanceof CellMapTimeLineActivity){
           isMapView = false;
       }else if(ctx instanceof CellMapSkipActivity){
           this.layout = R.layout.timeline_skip_item;
           isMapView = false;
       }
       options = new DisplayImageOptions.Builder()
        .showImageForEmptyUri(R.drawable.bg_cellmap_line)
        .showImageOnFail(R.drawable.bg_cellmap_line)
        .resetViewBeforeLoading()
        .cacheOnDisc()
        .imageScaleType(ImageScaleType.EXACTLY)
        .bitmapConfig(Bitmap.Config.RGB_565)
        .displayer(new FadeInBitmapDisplayer(300))
        .build();


       icoOptions = new DisplayImageOptions.Builder()
        .showImageForEmptyUri(R.drawable.pic)
        .showImageOnFail(R.drawable.pic)
        .resetViewBeforeLoading()
        .cacheOnDisc()
        .build();

       typefaceHelveticaBold = Typeface.createFromAsset(ctx.getAssets(), "HelveticaBold.ttf");

}

........... skip ..........

static class ViewHolder {
/////holder setting/////
}

@Override
public View getView(int position, View view, ViewGroup parent) {
    final ViewHolder holder;

    CellEntity row = new CellEntity();
    row = list.get(position);

    if(view == null){
        view = inflater.inflate(layout, parent , false);
        holder = new ViewHolder();
        holder.img_bottom_line =(ImageView)view.findViewById(R.id.img_bottom_line);
        holder.user_name = (TextView)view.findViewById(R.id.user_name);
        holder.likeCount = (TextView)view.findViewById(R.id.likeCount);
        holder.txt_like = (TextView)view.findViewById(R.id.txt_like);

        ......... skip ........

        view.setTag(holder);
    }else{
        holder = (ViewHolder) view.getTag();
    }

    ......... skip ........

    return view;
}

......... skip ........

}

就是这样。

我不明白为什么该列表视图调用getView方法21次甚至列表视图在列表中有20个项目!

0 个答案:

没有答案