我有一个gridview。该gridview包含imageview和布局。点击图片视图,我将布局背景设置为黑色,带有一些alpha。现在的问题是,假设我通过单击位置2处的imageview设置位置2的背景。现在当我点击位置4处的imageview时,位置4处的布局获得alpha背景但问题是位置2处的布局仍然具有阿尔法背景。我想要的是所有其他布局应设置为默认白色,只有点击的位置应具有该alpha背景。什么是解决方案。?
主要网格视图:
<GridView
android:id="@+id/productList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:verticalScrollbarPosition="right">
</GridView>
行项目:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="@dimen/padding_small">
<LinearLayout
android:id="@+id/mainLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="30dp"
android:orientation="horizontal"
android:padding="@dimen/padding_small">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_medium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/menu_foregroundcolor"
android:textSize="@dimen/text_medium" />
</LinearLayout>
<ImageView
android:id="@+id/mainLay_Alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="@dimen/padding_small"
android:src="@drawable/menu_down_icon" />
</LinearLayout>
GridView适配器:
public View getView(int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.each_product_item, null, true);
ImageView imageView = (ImageView) rowView.findViewById(R.id.mainLay_Alpha);
LinearLayout layout = (LinearLayout) rowView.findViewById(R.id.mainLay);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(productMoreOptOverlayId != null && productMoreOptOverlayId.getVisibility() == View.VISIBLE)
layout.setBackground
else
layout.removeBackground
}
});
return rowView;
};