获取黑屏,而滚动的ListView在Android中 [英] Getting Black Screen while Scrolling in ListView in Android

查看:271
本文介绍了获取黑屏,而滚动的ListView在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图中,我展示,我得到了,它运行得很好,模拟器和滚动亦数据。但是,当我测试器件在滚动它显示黑屏和之后的时间滚动停止它是在正常的可读形式。我不知道为什么会这样。我还附上样品code。

I have one listview in which i am displaying data that i got, it run fine in emulator and scroll also. But when i test it on device at the time of scrolling it is showing black screen and after scroll stops it is in the normal readable form. I don't why this is happening. I am also attaching sample code.

1日XML布局: -

1st XML Layout :-

<?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:orientation="vertical"
    android:padding="7dp" >

<TextView
    android:id="@+id/item_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:textColor="#000000"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textSize="20dp" />

<TextView
    android:id="@+id/item_subtitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:padding="2dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textSize="13dp" />

第二个ListView控件布局: - 它有滚动视图也

2nd ListView Layout :-It has scroll view also.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">   

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawSelectorOnTop="false" />

<TextView
    android:id="@android:id/empty"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="No data"
    android:textColor="#000000" />

code,其中我已经使用这个布局: -

Code where i have used this layouts :-

ListAdapter adapter = new SimpleAdapter(this, HomeMenuActivity.mylist , R.layout.listdata, 
            new String[] { "Name", "Vicinity" }, 
            new int[] { R.id.item_title, R.id.item_subtitle });

    setListAdapter(adapter);

    lv = getListView();
    lv.setTextFilterEnabled(true);

我有静态的ArrayListmylist中有数据。请,如果任何人有任何想法,为什么它显示黑屏在滚动的时候请指导我。

I have static arraylist "mylist" which has the data. Please if anyone has any idea that why it shows black screen at the time of scrolling please guide me.

感谢您         lv.setOnItemClickListener(本);

Thank you lv.setOnItemClickListener(this);

推荐答案

我与上述所有问题的答案完全一致,但让我给你这个信息:

I am totally agree with all the answers listed above, but let me give you this information:

ListView中有透明/半透明的背景默认情况下,而在Android的UI工具包使所有默认控件。这意味着,当ListView的重绘其子,它具有混合的儿童窗口的背景。再次,这需要从内存昂贵的回读的是滚动或者绘制发生十几每秒次一扔期间特别痛苦。

ListView has a transparent/translucent background by default, and so all default widgets in the Android UI toolkit. This implies that when ListView redraws its children, it has to blend the children with the window's background. Once again, this requires costly readbacks from memory that are particularly painful during a scroll or a fling when drawing happens dozen of times per second.

要改善在滚动操作绘图性能,Android框架重用缓存的颜色提示。当这个提示设置,框架复制列表中填充有提示值位图的每个子(假设其他的优化​​,称为滚动缓存,不关闭)。的ListView然后直接在屏幕上的blit这些位图和因为这些位图是已知的不透明,无混合是必需的。此外,由于默认的缓存淡淡的颜色为#191919,您滚动过程中获得的每一项后面的黑暗背景。

To improve drawing performance during scrolling operations, the Android framework reuses the cache color hint. When this hint is set, the framework copies each child of the list in a Bitmap filled with the hint value (assuming that another optimization, called scrolling cache, is not turned off). ListView then blits these bitmaps directly on screen and because these bitmaps are known to be opaque, no blending is required. Also, since the default cache color hint is #191919, you get a dark background behind each item during a scroll.

要解决此问题,所有你需要做的是要么禁用缓存的颜色提示优化,如果你使用非纯色背景,或设置提示到相应的纯色值。您可以从code做到这一点(请参阅 setCacheColorHint(INT) )或preferably从XML,使用了android:cacheColorHint属性。要禁用优化,简单地使用透明色#00000000。下面的截图显示一个列表的 安卓cacheColorHint =#00000000 在XML布局文件中设置

To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. You can do this from code (see setCacheColorHint(int)) or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000" set in the XML layout file

有关详细信息: Android的ListView的优化

您可以使用 安卓cacheColorHint =@机器人:彩色/透明 安卓:cacheColorHint =#00000000

You can either use android:cacheColorHint="@android:color/transparent" or android:cacheColorHint="#00000000"

这篇关于获取黑屏,而滚动的ListView在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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