ExpandableListView滚动时颜色改变(不是变黑)怎么解决?

书牍时光 发布于 2013/07/21 14:20
阅读 371
收藏 1
不是变黑!就是滚动时颜色会变化,很是影响视觉效果! 简化了的源码如下: 主程序: import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.TextView; public class MainActivity extends Activity { ExpandableListView TestList; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TestList = (ExpandableListView) findViewById(R.id.filelist); FolderAdapter folderAdapter = new FolderAdapter(); TestList.setGroupIndicator(null); TestList.setAdapter(folderAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } public class FolderAdapter extends BaseExpandableListAdapter { private List ListGroup, ListChild; public FolderAdapter() { ListGroup = new ArrayList(); for (int i = 0; i < 4; i++) { ListGroup.add("Group0" + (i + 1)); } ListChild = new ArrayList(); for (int i = 0; i < 40; i++) { if (i < 9) { ListChild.add("Child0" + (i + 1)); } else { ListChild.add("Child" + (i + 1)); } } } @Override public int getGroupCount() { return ListGroup.size(); } @Override public int getChildrenCount(int gp) { return ListChild.size(); } @Override public Object getGroup(int gp) { return ListGroup.get(gp); } @Override public Object getChild(int gp, int cp) { return ListChild.get(cp); } @Override public long getGroupId(int gp) { return gp; } @Override public long getChildId(int gp, int cp) { return cp; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int arg0, int arg1) { return true; } @Override public View getGroupView(final int gp, boolean isExpanded, View convertView, ViewGroup parent) { View view = convertView; if (view == null) view = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_group, null); TextView GROUPNAME = (TextView) view.findViewById(R.id.GROUPNAME); GROUPNAME.setText(ListGroup.get(gp)); if (TestList.isGroupExpanded(gp)) view.setBackgroundColor(Color.parseColor("#DFFFEF")); else view.setBackgroundColor(Color.parseColor("#DDEEFF")); return view; } @Override public View getChildView(final int gp, final int cp, boolean isLast, View convertView, ViewGroup parent) { if (convertView == null) convertView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_group, null); TextView GROUPNAME = (TextView) convertView.findViewById(R.id.GROUPNAME); GROUPNAME.setText(ListChild.get(gp)); if (cp >= 10 && cp <= 30) convertView.setBackgroundColor(Color.parseColor("#AADDEEEE")); else convertView.setBackgroundColor(Color.parseColor("#60A0A0A0")); return convertView; } } } activity_main.xml item_group.xml
加载中
返回顶部
顶部