Android fragments 片段中的minifab浮动操作按钮不可单击

Android fragments 片段中的minifab浮动操作按钮不可单击,android-fragments,kotlin,android-animation,floating-action-button,Android Fragments,Kotlin,Android Animation,Floating Action Button,我有一个浮动的动作按钮在一个片段内,还有3个其他的微型晶圆厂,它们以弧线的形式从中产生动画。主晶圆厂工作正常,并在微型晶圆厂上调用动画,但由于某些原因,微型晶圆厂无法单击。我可以轻松访问所有晶圆厂,但无法访问迷你晶圆厂的setOnClickListener()。布局如下: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http:

我有一个浮动的动作按钮在一个片段内,还有3个其他的微型晶圆厂,它们以弧线的形式从中产生动画。主晶圆厂工作正常,并在微型晶圆厂上调用动画,但由于某些原因,微型晶圆厂无法单击。我可以轻松访问所有晶圆厂,但无法访问迷你晶圆厂的
setOnClickListener()
。布局如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:fitsSystemWindows="true">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/chatter"
        android:textColor="@color/black" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_chatter_video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/fab_first_menu_item_margin_bottom"
        android:layout_marginEnd="@dimen/right_margin"
        android:clickable="true"
        android:focusable="true"
        android:visibility="visible"
        app:backgroundTint="@color/white"
        app:fabSize="mini"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/ic_chatter_new_video"
        android:fitsSystemWindows="true" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_chatter_open"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/fab_bottom_margin"
        android:layout_marginEnd="@dimen/fab_main_right_margin"
        android:clickable="true"
        android:focusable="true"
        android:visibility="visible"
        app:backgroundTint="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:fabSize="normal"
        app:srcCompat="@drawable/ic_chatter_new" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_chatter_photo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/fab_first_menu_item_margin_bottom"
        android:layout_marginEnd="@dimen/right_margin"
        android:clickable="true"
        android:focusable="true"
        android:visibility="visible"
        app:backgroundTint="@color/white"
        app:fabSize="mini"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/ic_chatter_new_photo" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_chatter_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/fab_first_menu_item_margin_bottom"
        android:layout_marginEnd="@dimen/right_margin"
        android:clickable="true"
        android:focusable="true"
        android:visibility="visible"
        app:backgroundTint="@color/white"
        app:fabSize="mini"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/ic_chatter_new_text" />

    <LinearLayout
        android:id="@+id/main_chatter_overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="0.45"
        android:orientation="vertical"
        android:visibility="invisible"
        android:background="@color/mainColor"
        />

</android.support.constraint.ConstraintLayout>

我正在用这段代码为fab_chatter_open制作动画,效果很好。单击动画和全部:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <rotate android:fromDegrees="45"
        android:toDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="300"
        android:interpolator="@android:anim/linear_interpolator"/>
</set>

第二次单击晶圆厂时反转此动画

然后我用这段代码来制作迷你工厂的动画。迷你晶圆厂上的动画效果很好,但晶圆厂无法以任何方式单击:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true" >

    <translate android:fromXDelta="82%p" android:toXDelta="65%p"
        android:fromYDelta="7%p" android:toYDelta="7%p"
        android:duration = "100"/>
    <alpha android:fromAlpha="0"
        android:toAlpha="1"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="100"/>
</set>


您还会注意到底部有一个
线性布局
。这是为了用50%的alpha覆盖recyclerView,以保持对晶圆厂的关注并使内容暗淡。不幸的是,它没有像我喜欢的那样覆盖actionbar或底部导航。如果您对实现这一点也有建议,请让我知道。

显然,在受约束的布局中,当您使用
translate
设置浮动动作按钮的动画时,按钮的点击会停留在创建和膨胀视图时最初绘制的位置。我决定在miniFabs浮动操作按钮上使用边距底部和边距末端:

android:layout_marginBottom=""
android:layout_marginEnd=""
当视图最初绘制并相对于主晶圆厂膨胀时,将浮动操作按钮放置在屏幕上我想要的位置。此外,由于这是一个受约束的布局,我使用了:

app:layout\u constraintBottom\u toBottomOf=“parent”
app:layout\u-toEndOf=“parent”

将按钮放在主晶圆厂所在的右下角,否则这些小型晶圆厂的利润底部和利润顶部将很难计算

然后我在miniFabs上使用animate
alpha
和animate
scale
。这会使迷你工厂在点击事件中保持在相同的位置,但会给他们一些动画,使他们有一点天赋


我还确保在将每个晶圆厂的可见性设置为gone后,将其
isEnabled()
属性设置为false,否则单击事件仍将存在。

我相信这与
translate
动画有关。如果我将迷你工厂设置为始终可见,我可以在动画完成之前单击迷你工厂。一旦动画开始,微型晶圆厂是不可点击的。