Scalified / fab

Floating Action Button Library for Android
Apache License 2.0
849 stars 164 forks source link

Animations not work #3

Closed Narayane closed 9 years ago

Narayane commented 9 years ago

Hi,

I have no animation either if they are defined in xml or if they are defined programmatically.

I put a fab in a relative layout as you advise it, with a recycler view. All is inflated in a fragment.

All others features work well.

I don't understand what I do wrong.

Thanks.

fragment_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/fragment_list_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/padding_default"/>

<com.software.shell.fab.FloatingActionButton
    android:id="@+id/fragment_list_fab"
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="@dimen/margin_default"
    android:layout_marginRight="@dimen/margin_default"
    android:layout_marginEnd="@dimen/margin_default"
    fab:type="normal"
    fab:shadow_color="@color/sq_blue_dark"
    fab:shadow_radius="8.0dp"
    fab:button_color="@color/sq_blue_dark"
    fab:button_colorPressed="@color/sq_orange_dark"/>

fragment onViewCreated

mFab = (FloatingActionButton) getSQActivity().findViewById(R.id.fragment_list_fab); mFab.setImageSize(24.0f); mFab.setImageDrawable(getResources().getDrawable(R.drawable.ic_add_white_24dp)); mFab.setAnimationOnShow(FloatingActionButton.Animations.ROLL_FROM_DOWN); mFab.setAnimationOnHide(FloatingActionButton.Animations.ROLL_TO_DOWN);

vbaidak commented 9 years ago

Hi,

Animations are played while calling public methods:

Could you please clarify the action for which you need the animation to be played

Thank you

Narayane commented 9 years ago

Hi,

it was the information which missed me. I had not even thought to check autocompletion for checking available methods ><.

You should add it in animation section of READ.md ;).

A suggestion: be able to set animation duration would be great !

Thanks !

vbaidak commented 9 years ago

Great, will add this into javadoc && README.md

For animation duration try this:

magicButton.getAnimationOnShow().setDuration(5000);
davicdsalves commented 9 years ago

How can I animate it when scrolling through a list?

vbaidak commented 9 years ago

Hi davicdsalves,

Action Button supports 2 animation types: animation, which is played while showing the button and animation, which is played while hiding the button. By default neither show animation, nor hide animation are set. Animations are played only if set when you call methods:

Thus, in order to make animations working when scrolling you need to do 2 things:

  1. Implement the scroll listener for you container (either ListView, ScrollView etc.)
  2. When detecting scroll up in listener call show() method, when detecting scroll down in listener call hide() method.

Don't forget to set animations before calling these methods

davicdsalves commented 9 years ago

Thanks for your response @shell-software, but don't you have a default implementation for this like other frameworks do? Since this behavior is expected to be used by many. I checked how floating-action-button from @shamaland was doing with it's ShowHideOnScroll, but decided to ask to see if I was missing some default listener here. Thanks again.

vbaidak commented 9 years ago

You're right, Action Button doesn't have default listeners for this.

This is so, because in fact such listeners are not the part of the Floating Action Button. Action Button gives you only a way to manage itself. It's up to you to decide how actually you need to manage it.

davicdsalves commented 9 years ago

I agree with you @shell-software, I'm just looking for an implementation by someone else so I don't have to reinvent it, since I'm 100% sure someone else had to do it. Thank you, great job on the framework.

jsiva001 commented 8 years ago

Hi shell-Software,

I have fragments in view pager and i have put fab in one specific fragment then now i have coded like this

    floatingActionButton = (ActionButton ) rootView.findViewById(R.id.float_Button);

    floatingActionButton.setType(ActionButton.Type.DEFAULT);

    floatingActionButton.setImageResource(R.mipmap.ic_mode_edit_white_24dp);

    floatingActionButton.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary));

    floatingActionButton.setShowAnimation(ActionButton.Animations.JUMP_FROM_DOWN);

    floatingActionButton.playShowAnimation();

but there is no animation playing when load the fragment in view pager ( while come to visible on this fragment)

where i have missed somethings? , Please let me know or else should add anything for play animation in view pager fragments, actually i need to play animation like jump from down and jump to down (page is visible and page is invisible state).

Thanks.

vbaidak commented 8 years ago

Hi jsiva001

This happens because animation is played before the action button is shown

Try setting the page listener and calling show() or hide() methods within its callbacks like this:

    pager.setOnPageChangeListener(new OnPageChangeListener() {

      @Override
      public void onPageSelected(int position) {
           actionButton.show();
      }

      @Override
      public void onPageScrolled(int position, float positionOffset,
          int positionOffsetPixels) {
      }

      @Override
      public void onPageScrollStateChanged(int state) {
      }
    });