0

I'm testing the use of Snackbar for the first time and I'm finding a behaviour which I don't understand. My Activity is composed of a Fragment, which is composed of a FrameLayout with a RecyclerView. I'm using Toolbar and Appbar.

When the Snackbar appears it moves the recyclerView up, I don't want it to behave like this, I want the Snackbar to show OVER the RecyclerView without moving it. I can however remove this from the Layout that contains the fragment:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

and then the Snackbar displays as I intend it to but of course my fragment overlaps with the Toolbar. I'm new to CoordinatorLayout so I fail to see how to get the behaviour I want. My full code is below.

My activity:

<? 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>

My fragment:

<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>

I'm using the Snack like thus, fL being the FrameLayout @+id/randomizerFragment.

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

Any help is welcome.

dbar
  • 1,740
  • 1
  • 16
  • 20
  • Am not not what you referred to in the snackback but the first paramaeter needs to be the id of the coordinator layout. Snackbar.make(master_coordinator_layout,"hey",....).show(); – Jude Fernandes Sep 24 '15 at 01:54
  • I have also tried that and it makes no difference on how the Snackbar behaves at least in this situation. I will leave it with the coordinator_layout since that seems to be the correct approach, thanks. – dbar Sep 24 '15 at 11:53

0 Answers0