//将点击时的背景色设置为透明
gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
此时点击GridView的每个Item就不会出现难看的背景色了。
为了有更好的用户体验,可以对每个Item添加动画:
gridView.setOnItemClickListener(new ItemClickListener());
此时点击Item时,图标就会有变化:
private class ItemClickListener implements OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { //对ItemImg添加点击动画
ImageView itemImg = (ImageView)arg1.findViewById(R.id.itemImg);
Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.item_img);
itemImg.startAnimation(animation);
}
}
动画文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="300"/>
</set>