协调器在 FloatingActionButton 下方布局 TextInput

Coordinator layout TextInput below FloatingActionButton

大家好,我在协调器布局方面遇到了问题。 我有 TextInputLayout,里面有 editText。 我想要的是在左侧单击 FAB 时显示它,在单击 FAB 时隐藏它。

但我总是对低于 FAB 的编辑文本有疑问:

我能够以某种方式做到这一点的唯一方法是使用 marginRight,请参阅下面的 xml。但是有没有办法做到这一点,我认为必须有更好的方法。

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="@dimen/fab_normal_size"
    android:layout_height="@dimen/fab_normal_size"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:fabSize="normal"
    android:src="@drawable/ic_add_black_24dp" />


<android.support.design.widget.TextInputLayout
    android:id="@+id/input_layout_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/fab"
    app:layout_anchorGravity="left|center_vertical"
    android:layout_marginRight="@dimen/fab_normal_size">

    <EditText
        android:id="@+id/input_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="banany"
        android:text="testestes....." />

FAB 总是结束 UI by design:

Floating action buttons are used for a special type of promoted action. They are distinguished by a circled icon floating above the UI and have special motion behaviors related to morphing, launching, and the transferring anchor point.

我还没有检查它是如何实现的,所以除非有人给出更好的答案,否则你可以检查 CoordinatorLayout 和 FAB 来源,看看是什么让它在 UI 上徘徊,或者如果时间很短,你只需放置一些看起来像 FAB 的东西 (你可以使用带有适当可绘制对象的常规按钮,或使用第 3 方库)。

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/fab"
        app:layout_anchorGravity="left|center_vertical">

    <EditText
        android:id="@+id/input_txt"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginLeft="10dp"
        android:hint="banany"
        android:text="testestes....." />

    </android.support.design.widget.TextInputLayout>

试试上面的代码,希望能在一定程度上达到目的