Java 在其他gridview行中隐藏布局,并仅在单击位置时显示
我有一个网格视图。该gridview包含一个imageview和一个布局。单击imageview,我将布局背景设置为带有一些alpha的黑色。现在的问题是,假设我通过单击位置2的imageview在位置2上设置背景。现在,当我单击位置4处的imageview时,位置4处的布局获得alpha背景,但问题是位置2处的布局仍然具有alpha背景。我想要的是,所有其他布局都应该设置为默认白色,并且只有单击的位置应该具有alpha背景。这个问题的解决办法是什么 主网格视图:Java 在其他gridview行中隐藏布局,并仅在单击位置时显示,java,android,android-layout,gridview,Java,Android,Android Layout,Gridview,我有一个网格视图。该gridview包含一个imageview和一个布局。单击imageview,我将布局背景设置为带有一些alpha的黑色。现在的问题是,假设我通过单击位置2的imageview在位置2上设置背景。现在,当我单击位置4处的imageview时,位置4处的布局获得alpha背景,但问题是位置2处的布局仍然具有alpha背景。我想要的是,所有其他布局都应该设置为默认白色,并且只有单击的位置应该具有alpha背景。这个问题的解决办法是什么 主网格视图: <GridView
<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>
显示一些代码以便更好地帮助您实际上我没有包含代码,因为它是一个带有适配器的简单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>
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;
};