apply PageTransformer to PagerView as soon as possible

后端 未结 2 1106
抹茶落季
抹茶落季 2021-01-13 10:56

I have a PageTransfomer applied to a ViewPager, it works great but I want to launch the page\'s transformation as soon as I set the PageTransformer to the ViewPager. I alrea

2条回答
  •  时光说笑
    2021-01-13 11:21

    Based on Oleg's answer is used the code below for my app.

    My addition is to check the returned result of beginFakeDrag() inside _invalidatePageTransformer.

    I call sendInvalidatePageTransformer() from inside

    • onConfigurationChanged() when the orientation changed
    • inside the LoaderCallback-methods in my Fragment

      private Handler handler = new Handler()
      {
              public void handleMessage(Message msg)
              {
                      switch(msg.what)
                      {
                              case 0:
                                      _invalidatePageTransformer();
                                      break;
                      }
              }
      };
      
      private void _invalidatePageTransformer()
      {
              //no need to invalidate if we have no adapter or no items
              if (this.getAdapter() != null && this.getAdapter().getCount() > 0)
              {
                      //import check here, only fakeDrag if "beginFakeDrag()" returns true
                      if (this.beginFakeDrag())
                      {
                              this.fakeDragBy(0f);
                              this.endFakeDrag();
                      }
              }
      }
      
      public void sendInvalidatePageTransformer()
      {
              this.handler.sendEmptyMessage(0);
      }
      

    EDIT: Note: This code is located inside a custom ViewPager-subclass

提交回复
热议问题