[英]Cannot click my floating action button which is above a scroll view
我有一個CoordinatorLayout
,里面有兩個FloatingActionButton
,下面是ScrollView
。
問題是,即使我可以在屏幕上看到我的FloatingActionButtons
,也無法單擊它們。 我懷疑這是因為所有onTouch
事件都是從ScrollView
處理的
這是我的布局xml(可能很糟糕,因此歡迎任何提示):
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Note: that 80dp padding is:
main_padding + fab_size + 8dp = 80dp
16dp + 56dp + 8dp = 80dp
and it was the only way I could think to add padding
between my FABs
I tried to use app:layout_anchor but my 2
FABs had no padding between them... -->
<android.support.design.widget.FloatingActionButton
style="@style/RefreshFab"
android:id="@+id/fab_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="80dp"
android:layout_marginEnd="16dp"
app:fabSize="normal"
app:pressedTranslationZ="12dp"/>
<android.support.design.widget.FloatingActionButton
style="@style/SendFab"
android:id="@+id/fab_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
app:fabSize="normal"
app:elevation="6dp"
app:pressedTranslationZ="12dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Toolbar -->
<include
layout="@layout/view_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<!-- Much stuff here, text views, spinners etc.. -->
</LinearLayout>
</ScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
問題是因為每個項目都以在xml中寫入的相同順序布置在CoordinatorLayout中。 按照這種邏輯,將FloatingActionButtons分別放置在屏幕上,然后將LinearLayout放在它們的頂部,因此,我希望單擊被LinearLayout覆蓋。
重新排列XML以將FloatingActionButtons放在最后 ,這樣,可以說它們在布局的“頂部”。 然后,他們會很好地檢測到您的點擊監聽器。
我認為問題將持續存在,因為每個FloatingActionButton都包裝在具有match_parent尺寸的FrameLayout中。 我不認為您需要這些FrameLayouts,但是您只需將FloatingActionButtons放在CoordinatorLayout中即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.