Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在其他gridview行中隐藏布局,并仅在单击位置时显示_Java_Android_Android Layout_Gridview - Fatal编程技术网

Java 在其他gridview行中隐藏布局,并仅在单击位置时显示

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包含一个imageview和一个布局。单击imageview,我将布局背景设置为带有一些alpha的黑色。现在的问题是,假设我通过单击位置2的imageview在位置2上设置背景。现在,当我单击位置4处的imageview时,位置4处的布局获得alpha背景,但问题是位置2处的布局仍然具有alpha背景。我想要的是,所有其他布局都应该设置为默认白色,并且只有单击的位置应该具有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>

显示一些代码以便更好地帮助您实际上我没有包含代码,因为它是一个带有适配器的简单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;

    };