因为我正在开发API级别7以上,所以setAlpha(float)对我无效。因此我已经实现了遍历给定ViewGroup的所有子元素的方法,并试图找到设置alpha的方法,以便元素几乎是透明的。不幸的是,我不能想出一种方法来使listview及其项目透明。我如何继续?如何设置列表视图中所有项目的alpha值?
public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled)
{
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = viewGroup.getChildAt(i);
view.setEnabled(enabled);
if(!enabled) {
if(view instanceof TextView) {
int curColor = ((TextView) view).getCurrentTextColor();
int myColor = Color.argb(ALPHA_NUM, Color.red(curColor),
Color.green(curColor),
Color.blue(curColor));
((TextView)view).setTextColor(myColor);
}
else if(view instanceof ImageView)
{
((ImageView) view).setAlpha(ALPHA_NUM);
}
else if(view instanceof ListView)
{
// How do I set the text color of the subitems in this listview?
}
else
{
try
{
Paint currentBackgroundPaint = ((PaintDrawable) view.getBackground()).getPaint();
int curColor = currentBackgroundPaint.getColor();
int myColor = Color.argb(ALPHA_NUM, Color.red(curColor), Color.green(curColor), Color.blue(curColor));
view.setBackgroundColor(myColor);
}catch(NullPointerException e)
{
Log.d("viewNotFound", "View " + view.getId() + " not found..");
e.getStackTrace();
}
}
if (view instanceof ViewGroup) {
enableDisableViewGroup((ViewGroup) view, enabled);
} } }
请发布您的lsitview的适配器代码。您将希望能够在适配器处理您的列表视图子项时执行此类操作。 – petey 2013-02-25 17:20:23
没有什么值得一看的。 listView.setAdapter(new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,items)); –
CodePrimate
2013-02-25 17:21:15