如果想要disable掉GridView中的item,需要做如下两件事情:
1. override Adapter 的 areAllItemsEnabled
2. override Adapter 的 isEnabled(int position)
3. 另外如果想在disable的时候,置灰对应的item,那么只需要在getView方法中,设置对应View的alpha值即可。
比如:
class MyAdapter extends BaseAdapter { @Override public boolean isEnable(int position) { // return true for clickable , false for not return isShouldEnableItem(position); } @Override public boolean areAllItemsEnabled() { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { ... if (isEnabled(position)) { convertView.setAlpha(1f); } else { convertView.setAlpha(0.2f); } ... } }
PS: the alpha value , 0 means the view is completely transparent and 1 means the view is completely opaque.
置灰GridView 的disable Item
时间: 2024-11-07 18:55:10