繁体   English   中英

滚动时可扩展列表Android黑色背景

[英]Expandable List Android Black background while scrolling

我正在努力使用Android中的ExpandableList视图。 我正在使用apis演示中提供的代码,但我不知道如何解决我的问题。

我的视图中有一个白色背景但是当我滚动列表时它会变黑。为什么?

我不想要这种效果......有没有办法改变它? 有没有办法使用此代码自定义列表? 我正在寻找这样的东西..希望你能帮助我! 谢谢 :)

package com.example.android.apis.view;

import android.R;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Demonstrates expandable lists backed by a Simple Map-based adapter
 */
public class ExpandableList3 extends ExpandableListActivity {
    private static final String NAME = "NAME";
    private static final String IS_EVEN = "IS_EVEN";

    private ExpandableListAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
        List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
        for (int i = 0; i < 20; i++) {
            Map<String, String> curGroupMap = new HashMap<String, String>();
            groupData.add(curGroupMap);
            curGroupMap.put(NAME, "Group " + i);
            curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");

            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            for (int j = 0; j < 15; j++) {
                Map<String, String> curChildMap = new HashMap<String, String>();
                children.add(curChildMap);
                curChildMap.put(NAME, "Child " + j);
                curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
            }
            childData.add(children);
        }

        // Set up our adapter

        mAdapter = new SimpleExpandableListAdapter(
                this,
                groupData,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 },
                childData,
                R.layout.simple_expandable_list_item_3,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 }
                );

        setListAdapter(mAdapter);
    }

}

添加到xml文件中的列表视图:

android:cacheColorHint="#00000000"

或者在您的Java代码中:

getListView().setCacheColorHint(0);

android:cacheColorHint="#00000000"到ListView

例;

<ListView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/list"
   android:cacheColorHint="#00000000" />

在xml中写下这个,你就会得到答案

机器人:scrollingCache = “假”

按照此链接上的说明操作:

Android开发人员资源:Listview背景

简而言之:...要解决此问题,您需要做的就是禁用缓存颜色提示优化,如果使用非纯色背景,或将提示设置为适当的纯色值。 您可以使用android:cacheColorHint属性从代码(请参阅setCacheColorHint(int))或最好从XML执行此操作。 要禁用优化,只需使用透明色#00000000。 以下屏幕截图显示了在XML布局文件中设置android:cacheColorHint =“#00000000”的列表...

只需使用以下方法设置列表颜色:

android:cacheColorHint="#000000"

或者在您的Java代码中:

listView.setCacheColorHint(0);

我只想指出,有一种表达#00000000的更优雅方式,只需使用: @android/color/transparent 如果你以后回到那段代码会更容易理解(是的,我知道它只是一个ARGB号码;-))。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM