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 回答