0

Snackbar の使用を初めてテストしていますが、理解できない動作を見つけています。私のアクティビティは、RecyclerView を持つ FrameLayout で構成される Fragment で構成されています。ツールバーとアプリバーを使用しています。

Snackbar が表示されると、recyclerView が上に移動します。このように動作させたくありません。Snackbar を移動せずに RecyclerView の上に表示する必要があります。ただし、フラグメントを含むレイアウトからこれを削除できます。

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

そして、意図したとおりにスナックバーが表示されますが、もちろん私のフラグメントはツールバーと重なっています。CoordinatorLayout は初めてなので、必要な動作を取得する方法がわかりません。私の完全なコードは以下のとおりです。

私の活動:

<? xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/master_coordinator_layout"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:animateLayoutChanges="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include
            android:id="@+id/toolbar_home"
            layout="@layout/toolbar_default"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <FrameLayout
            android:id="@+id/randomizerFragment"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        </FrameLayout>
        <FrameLayout
            android:id="@+id/randomizerScreenFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone">
        </FrameLayout>
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/randomizeFAB"
        android:src="@drawable/ic_play_arrow_white_24dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="40dp"
        app:backgroundTint="@color/myYellow"
        app:fabSize="normal"
        app:layout_anchor="@id/randomizerFragment"
        android:scaleType="center"
        app:layout_anchorGravity="top|right"
        android:visibility="invisible" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/resetFAB"
        android:src="@drawable/ic_replay_white_24dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="60dp"
        app:backgroundTint="@color/myOrange"
        app:fabSize="mini"
        app:layout_anchor="@id/randomizerScreenFragment"
        android:scaleType="center"
        app:layout_anchorGravity="top|right"
        android:visibility="invisible" />
</android.support.design.widget.CoordinatorLayout>

私のフラグメント:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          tools:context=".RandomizerActivity"
          android:orientation="vertical"
          android:animateLayoutChanges="true">

<android.support.v7.widget.RecyclerView
    android:id="@+id/factionsRecyclerView"
    android:paddingTop="@dimen/margin_small"
    android:layout_width="match_parent"
    android:clipToPadding="false"
    android:layout_height="wrap_content"/>
</LinearLayout>

このようにスナックを使用しています.fLはFrameLayout @ + id/randomizerFragmentです。

Snackbar.make(fL, "hey!", Snackbar.LENGTH_SHORT).show();

どんな助けでも大歓迎です。

4

0 に答える 0