0

いくつかの試行の後、フローティングボタンをクリックすると半透明の背景を生成できます。現在の問題は、「新しい背景」が色を変更するだけであることです。この下にリサイクルビューがあり、上下にスワイプして操作できます。私が今必要としているのは、私が見えるようにするレイアウトの下のrecyclerviewですべてのアクションを防ぐことです。私ができる唯一のことは次のとおりです。

  • 半透明のビューをクリックすると、ファブが崩壊します

これは実際に使用するコードです:

OnClickListener listener = new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            if (DrawerActivity.instance.rootFab.isExpanded())
            {
                whiteLayout.setVisibility(View.GONE);
            }
            else
            { 
                whiteLayout.setVisibility(View.VISIBLE);

            }
            mainFab.toggle();
        }
    };

そしてもちろん:

rootFab.setAddButtonClickListener(listener);

それにリスナーを与えるために。したがって、単純に、メイン fab (私は複数の fab を持つライブラリを使用しています) をクリックすると、次のようなレイアウトが表示されます。

----
----
 <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
        <LinearLayout
            android:id="@+id/semi_white_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_semi_transparent"
            android:orientation="vertical"
            android:visibility="gone" >
        </LinearLayout>
---
---

そして、fabをもう一度押すと、レイアウトが消えます...だから私の質問は、どうすれば同じことを行うことができますか?

4

1 に答える 1

2

ビューが「クリック可能」であることを Android に伝えることができます。このようにして、ビューはタッチ イベントを消費し、さらにRecyclerView.

ビューを「クリック可能」としてマークするには、xml レイアウトに次のフラグを追加するだけですandroid:clickable="true":

----
----
 <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
        <LinearLayout
            android:id="@+id/semi_white_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_semi_transparent"
            android:orientation="vertical"
            android:clickable="true"
            android:visibility="gone" >
        </LinearLayout>
---
---

また、ビューを単なる背景として使用する場合、 Heavy-weight が必要な理由はわかりませんLinearLayout。ここで使用できViewます:

----
----
 <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
        <View
            android:id="@+id/semi_white_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_semi_transparent"
            android:clickable="true"
            android:visibility="gone" />
---
---
于 2015-03-30T22:29:14.167 に答える