2

現在、作成中のアプリにフローティング アクション ボタンを設定しています。私の問題は、ボタンをクリックすると、ボタンの背後にあるリストビューもクリックイベントを受け取ることです。ボタンがクリックイベント全体を消費するようにする必要があります。

このライブラリを使用してボタンを作成しています: https://github.com/FaizMalkani/FloatingActionButton

これを達成する方法について誰かが私を正しい方向に向けることができれば、それは大歓迎です。以下に使用しているxmlレイアウトを含めました。

ありがとうコーリー:)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:padding="4dip"
    android:gravity="center_horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:padding="4dip"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1">

        </android.support.v4.view.ViewPager>

    </LinearLayout>

    <com.bacon.corey.audiotimeshift.FloatingActionButton
        android:id="@+id/fabbutton"
        android:layout_width="72dp"
        android:layout_height="72dp"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        app:colour="@color/holo_red_light"
        app:drawable="@drawable/ic_content_new"

    />

</FrameLayout>
4

1 に答える 1

5

FloatingActionButton の実装の詳細はわかりませんが、TouchListener を設定して、onTouch メソッドから true を返すイベントを消費できます。このようなもの:

mFloatingActionButton.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP){
            // Do what you want
            return true;
        }
        return true; // consume the event
    }
});
于 2014-11-14T14:26:35.483 に答える