Android的ListView的项目重叠,同时滚动 [英] Android ListView items overlap while scrolling

查看:194
本文介绍了Android的ListView的项目重叠,同时滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用的CursorAdapter 的自定义实现实施的ListView 。我的问题是,每当我一扔(启动应用程序后右)以快速滚动到列表的底部,我有时画互相重叠的所有的ListView项目结束。如果我滚动备份或触摸的项目之一,成为他们妥善安排。

下面是如何看起来后,我赶紧向下滚动:
http://i.stack.imgur.com/cTcfD.png

下面是如何看起来,当我选择 - ING 的项目之一:
http://i.stack.imgur.com/ZTRSt.png

下面是XML我的的ListView

 < ListView控件
        机器人:ID =@ + ID / all_reminders_list
        机器人:paddingLeft =4DP
        机器人:paddingRight =4DP
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =1
        机器人:layout_alignParentLeft =真
        机器人:可点击=真
        机器人:dividerHeight =1.0sp
        机器人:animateLayoutChanges =真正的>

下面是我的自定义的CursorAdapter的 NewView的(..)方法:

 公开查看NewView的(上下文的背景下,光标光标的ViewGroup父){
    LayoutInflater充气= LayoutInflater.from(parent.getContext());
    查看查看= inflater.inflate(R.layout.view_list_item,父母,假);
    返回视图。
}

和这是 bindView(..)方法:

 公共无效bindView(查看视图,上下文的背景下,光标光标){        TextView的whatTextView =(TextView中)view.findViewById(R.id.item_what_text);
        whatTextView.setText(cursor.getString(1));
        TextView的whenTextView =(TextView中)view.findViewById(R.id.item_when_text);
        如果(cursor.getInt(9)!= 0)// DONE_FLAG = 1(已完成)
        {
            //箭知名度
            ImageView的箭头=(ImageView的)view.findViewById(R.id.list_item_arrow);
            arrow.setVisibility(View.INVISIBLE);            //文本颜色
            whatTextView.setTextColor(Color.LTGRAY);
            whenTextView.setTextColor(Color.LTGRAY);            //当文字
            whenTextView.setText(TimeCalculationHelper.getCompletedTimeString(cursor.getLong(2)));
        }
        否则// DONE_FLAG = 0
        {
            //箭知名度
            ImageView的箭头=(ImageView的)view.findViewById(R.id.list_item_arrow);
            arrow.setVisibility(View.VISIBLE);            //文本颜色
            whatTextView.setTextColor(Color.BLACK);
            whenTextView.setTextColor(Color.BLACK);            //当文字
            whenTextView.setText(TimeCalculationHelper.getTimeRemainingString(cursor.getLong(2)));
        }
}

我也注意到,我已经能够复制它,只有当我的设备(银河S2)处于省电模式。是不是我应该做不同吗?在此先感谢!

修改:包括列表项的布局

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向
    机器人:paddingLeft =2DP>< TextView的机器人:ID =@ + ID / item_what_text
          机器人:行=1
          机器人:MAXLINES =2
          机器人:TEXTSIZE =22dp
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:paddingTop =3DP/>< TextView的机器人:ID =@ + ID / item_when_text
          机器人:行=1
          机器人:MAXLINES =1
          机器人:TEXTSIZE =14dp
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:文字=13分钟
          机器人:paddingBottom会=2DP
          机器人:layout_below =@ + ID / item_what_text/>< ImageView的
    机器人:ID =@ + ID / list_item_arrow
    机器人:SRC =@绘制/下一个
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentRight =真
    机器人:layout_centerVertical =真/>
< / RelativeLayout的>


解决方案

我也面临同样的问题,在我的ListView列表项相互重叠,同时滚动。

我的修正:
我只是指定所包含的问题ListView的父布局的背景。 previously它是透明的。

I have implemented a ListView in my application using a custom implementation of CursorAdapter. My problem is, that whenever I fling to scroll quickly to the bottom of the list (right after launching the application), I sometimes end up with all the ListView items drawn overlapping each other. If I scroll back up or touch one of the items, they become properly arranged.

Here is how it looks after I quickly scroll down : http://i.stack.imgur.com/cTcfD.png

Here is how it looks when I am select-ing one of the items : http://i.stack.imgur.com/ZTRSt.png

Here is the XML for my ListView :

<ListView
        android:id="@+id/all_reminders_list"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:layout_alignParentLeft="true"
        android:clickable="true"
        android:dividerHeight="1.0sp"
        android:animateLayoutChanges="true">

Here's the newView(..) method of my custom CursorAdapter :

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View view = inflater.inflate(R.layout.view_list_item, parent, false);
    return view;
}

And this is the bindView(..) method :

    public void bindView(View view, Context context, Cursor cursor) {

        TextView whatTextView = (TextView) view.findViewById(R.id.item_what_text);
        whatTextView.setText(cursor.getString(1));
        TextView whenTextView = (TextView) view.findViewById(R.id.item_when_text);


        if(cursor.getInt(9) != 0) // DONE_FLAG = 1 (completed)
        {
            //Arrow visibility
            ImageView arrow = (ImageView)view.findViewById(R.id.list_item_arrow);
            arrow.setVisibility(View.INVISIBLE);

            //Text color
            whatTextView.setTextColor(Color.LTGRAY);
            whenTextView.setTextColor(Color.LTGRAY);

            //WHEN text
            whenTextView.setText(TimeCalculationHelper.getCompletedTimeString(cursor.getLong(2)));
        }
        else // DONE_FLAG = 0
        {
            //Arrow visibility
            ImageView arrow = (ImageView)view.findViewById(R.id.list_item_arrow);
            arrow.setVisibility(View.VISIBLE);

            //Text color
            whatTextView.setTextColor(Color.BLACK);
            whenTextView.setTextColor(Color.BLACK);

            //WHEN text
            whenTextView.setText(TimeCalculationHelper.getTimeRemainingString(cursor.getLong(2)));


        }
}

I've also noticed that I have been able to replicate it only when my device (Galaxy S2) is in power saving mode. Is there something I should be doing differently here? Thanks in advance!

EDIT : Including the list item's layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingLeft="2dp">

<TextView android:id="@+id/item_what_text"
          android:lines="1"
          android:maxLines="2"
          android:textSize="22dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingTop="3dp"/>

<TextView android:id="@+id/item_when_text"
          android:lines="1"
          android:maxLines="1"
          android:textSize="14dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="13 minutes"
          android:paddingBottom="2dp"
          android:layout_below="@+id/item_what_text"/>

<ImageView
    android:id="@+id/list_item_arrow"
    android:src="@drawable/next"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"/>


</RelativeLayout>

解决方案

I also faced the same problem, with List items in my ListView overlapping each other whilst scrolling.

My fix: I just specified a background for the parent layout that contained the ListView in question. Previously it was transparent.

这篇关于Android的ListView的项目重叠,同时滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆