我正在设置我正在制作的应用中的浮动操作按钮。 我的问题是当我点击按钮时,按钮后面的列表视图也会收到点击事件。 我需要这样做,以便按钮消耗整个点击事件。
我正在使用此库创建按钮: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>
答案 0 :(得分: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
}
});