gowong / material-sheet-fab

Android library that provides the floating action button to sheet transition from Google's Material Design.
MIT License
1.58k stars 255 forks source link

FAB does not return the correct position on Android < 5.0 #5

Closed dniHze closed 9 years ago

dniHze commented 9 years ago

Great lib, but... On Lollipop and higher all is going smooth and nice, on API 19 and lower fab going higher. Everything was made due to example. Stacked on it, help plz.

gowong commented 9 years ago

Sorry, I don't understand what the issue is. Maybe a screenshot would help?

aldefy commented 9 years ago

I would like to add details on this : on pre lollipop , once the fab is clicked the sheet appears but soon after it dismisses , fab position keeps moving up , its not tethered to its original position , some issue with transitions

gowong commented 9 years ago

Okay, I think I get what you're saying. Does the sample app work properly on your device? Just to make sure, you're using the latest version of the library right? I experienced the same issue you mentioned but 3ec8b548a41c20c4a5f5c303cbaee3a372266f06 fixed it in v1.0.1

aldefy commented 9 years ago

yes 1.02 is what im using , but , on pre lollipop the fab hovers to new positions and anchors there , where as it should be on right bottom , after first click it moves up and stays there

gowong commented 9 years ago

I see. Do you mind sharing the code for your FAB implementation as well as how you are hiding and showing the FAB? Also, are you using android.support.design.widget.FloatingActionButton? I believe v23 of the design library was recently released so I wonder if there's an issue with the latest version.

aldefy commented 9 years ago

Java :

        int sheetColor = getResources().getColor(R.color.white);
        int fabColor = getResources().getColor(R.color.accent);

        // Create material sheet FAB
        materialSheetFab = new MaterialSheetFab<>(locateFab, fabSheet, overlay, sheetColor, fabColor);

        // Set material sheet event listener
        materialSheetFab.setEventListener(new MaterialSheetFabEventListener() {
            @Override
            public void onShowSheet() {
                fabHoverText.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onHideSheet() {
                // Restore status bar color
                // setStatusBarColor(statusBarColor);
                fabHoverText.setVisibility(View.VISIBLE);
            }
        });

        popHeader.setText("Filter Bills");
        String[] filterList = getActivity().getResources().getStringArray(R.array.filter_bills);
        listView.setAdapter(new ArrayAdapter<String>(getActivity(),
                R.layout.adapter_item_fab_pop, android.R.id.text1, filterList));
        listView.setItemChecked(0, true);
        listView.setSelection(0);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Logger.d("Filter bills list click", position + "");
                fabHoverText.setText((String) listView.getAdapter().getItem(position));
                switch (position) {

                    default:
                        break;

                }
                materialSheetFab.hideSheet();
            }
        });

        buttonFilterOne.setText(popTabTitle[0]);
        buttonFilterTwo.setText(popTabTitle[1]);
        buttonFilterThree.setVisibility(View.VISIBLE);
        buttonFilterThree.setText(popTabTitle[2]);

FAB.java :

import android.content.Context;
import android.support.design.widget.FloatingActionButton;
import android.util.AttributeSet;

import com.gordonwong.materialsheetfab.AnimatedFab;

public class FAB extends FloatingActionButton implements AnimatedFab {

    private static final int FAB_ANIM_DURATION = 200;

    public FAB(Context context) {
        super(context);
    }

    public FAB(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FAB(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * Shows the FAB.
     */
    @Override
    public void show() {
        // Animate the FAB into view or simply set its visibility
    }

    /**
     * Shows the FAB and sets the FAB's translation.
     *
     * @param translationX translation X value
     * @param translationY translation Y value
     */
    @Override
    public void show(float translationX, float translationY) {
        // This is only needed if you want to support moving
        // the FAB around the screen.
    }

    /**
     * Hides the FAB.
     */
    @Override
    public void hide() {
        // Animate the FAB out of view or simply set its visibility
    }
}

and then XML :

    <!-- Your FAB implementation -->
    <views.FAB
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/icon_fab_filter"
        app:borderWidth="0dp"
        app:fabSize="normal" />

    <!-- Overlay that dims the screen -->
    <com.gordonwong.materialsheetfab.DimOverlayFrameLayout
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Circular reveal container for the sheet -->
    <io.codetail.widget.RevealLinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="right|bottom"
        android:orientation="vertical">

        <!-- Sheet that contains your items -->
        <android.support.v7.widget.CardView
            android:id="@+id/fab_sheet"
            style="@style/Widget.MaterialSheetFab.Sheet">

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="280dp"
                android:layout_height="300dp"
                android:orientation="vertical"
                tools:background="@color/red_500">

                <TextView
                    android:id="@+id/popHeader"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="16dp"
                    android:text="Filter"
                    android:textColor="@color/primary"
                    android:textSize="20sp" />

                <ListView
                    android:id="@+id/list"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/buttonGroupFilter"
                    android:layout_below="@+id/popHeader"
                    android:layout_marginBottom="5dp"
                    android:listSelector="@color/accent_light" />

                <GroupButtonView xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/buttonGroupFilter"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:orientation="horizontal"
                    segmentedgroup:border_width="0dp"
                    segmentedgroup:corner_radius="0dp"
                    segmentedgroup:tint_color="@color/primary_light"
                    tools:visibility="gone">

                    <RadioButton
                        android:id="@+id/buttonFilterOne"
                        style="@style/RadioButton"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:checked="true"
                        android:text="One" />

                    <RadioButton
                        android:id="@+id/buttonFilterTwo"
                        style="@style/RadioButton"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Two" />

                    <RadioButton
                        android:id="@+id/buttonFilterThree"
                        style="@style/RadioButton"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:checked="true"
                        android:text="Three"
                        android:visibility="gone" />
                </GroupButtonView >
            </RelativeLayout>
        </android.support.v7.widget.CardView>

    </io.codetail.widget.RevealLinearLayout>
aldefy commented 9 years ago

Hi any updates ?

gowong commented 9 years ago

Just released v1.0.3 which fixes this issue. It's on jcenter now and should be on maven central in a couple of hours.

aldefy commented 9 years ago

Thanks , im checking , but looks solid now , good work , out of curiosity what caused this behaviour ?