Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于RelateSlider平滑度的建议与修改,望作者重视 #49

Open
Paul-KK opened this issue Dec 31, 2016 · 9 comments
Open

关于RelateSlider平滑度的建议与修改,望作者重视 #49

Paul-KK opened this issue Dec 31, 2016 · 9 comments

Comments

@Paul-KK
Copy link

Paul-KK commented Dec 31, 2016

首先非常感谢作者的这个开源库,网上很多swipeback的开源库,但是你这个和其他最大的区别就是有微信联动效果,曾经我想实现微信联动效果,始终没有实现,最终在网上找到了你的这个开源库,顺利的解决了我的需求。但是在使用这个库的时候发现存在很多问题,最明显的一个是statusbar闪烁问题,看到别人也有提到这个问题,另一个就是开启微信联动功能会导致卡顿,特别是滑动松手后上一级activity会一顿一顿地,经过多版迭代后始终没有得以解决,然后我就认真研究了你的这个开源库,目前算是找到了一些优化方案,我想有必要通知你,更加完善这个开源库。
问题1:statusbar闪烁问题,这个是由于该库插入的layout并不能覆盖到statusbar,这是因为statusbar比较特殊,所以需要去掉系统的statusbar自己重绘。
问题2:RelateSlider联动卡顿问题,需要把RelateSlider里面的setX()函数换成setScrollX()函数,就会得到明显的改善。
问题3:如果在activity已经加载完成后再进行setSwipeEnable就会造成某些View如Switch的isLaidOut()函数始终为false,导致动画丢失。具体修改方案我会贴出代码。
问题4:新版本代码有问题,如果把setSwipeEnable设置为false以及禁止联动,就会导致背景透明,我看到也有人提到这个问题,原版是没有问题的,是因为新版额onPostCreate里面发生变化。改回原版就没问题。

以下是代码,希望作者能够关注和参考,大家一起完善这个开源库,让更多的人能够正常使用。

`package com.jude.swipbackhelper;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.ViewGroup;

/**

  • Created by Mr.Jude on 2015/8/3. 每个滑动页面的管理
    */
    public class SwipeBackPage {
    Activity mActivity;
    SwipeBackLayout mSwipeBackLayout;
    RelateSlider slider;

    SwipeBackPage(Activity activity) {
    this.mActivity = activity;
    }

    // 页面的回调用于配置滑动效果
    void onCreate() {
    mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mActivity.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);

     mSwipeBackLayout = new SwipeBackLayout(mActivity);
     mSwipeBackLayout.setLayoutParams(
     		new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
     slider = new RelateSlider(this);
    

    }

    void onPostCreate() {
    mSwipeBackLayout.attachToActivity(mActivity);
    }

    public SwipeBackPage setSwipeRelateEnable(boolean enable) {
    slider.setEnable(enable);
    return this;
    }

    public SwipeBackPage setSwipeRelateOffset(int offset) {
    slider.setOffset(offset);
    return this;
    }

    /**

    • 是否可滑动【activity的onWindowFocusChanged之前】调用本方法,
    • 之后请调用{@link #setSwipeBackEnableAfteronWindowFocusChanged()}
      */
      public SwipeBackPage setSwipeBackEnableBeforeonWindowFocusChanged(boolean enable) {
      if (enable) {
      mSwipeBackLayout.attachToActivity(mActivity);
      } else {
      mSwipeBackLayout.removeFromActivity(mActivity);
      }
      mSwipeBackLayout.setEnableGesture(enable);
      return this;
      }

    /**

    • 是否可滑动【activity的onWindowFocusChanged之后】调用本方法,
    • 之前请调用{@link #setSwipeBackEnableBeforeonWindowFocusChanged()}
    • 如果在onWindowFocusChanged之后调用{@link #setSwipeBackEnableBeforeonWindowFocusChanged()},
    • 则会使某些View如Switch的isLaidOut()函数始终为false,导致动画丢失
      */
      public SwipeBackPage setSwipeBackEnableAfteronWindowFocusChanged(boolean enable) {
      mSwipeBackLayout.setEnableGesture(enable);
      return this;
      }

    // 可滑动的范围。百分比。200表示为左边200px的屏幕
    public SwipeBackPage setSwipeEdge(int swipeEdge) {
    mSwipeBackLayout.setEdgeSize(swipeEdge);
    return this;
    }

    // 可滑动的范围。百分比。0.2表示为左边20%的屏幕
    public SwipeBackPage setSwipeEdgePercent(float swipeEdgePercent) {
    mSwipeBackLayout.setEdgeSizePercent(swipeEdgePercent);
    return this;
    }

    // 对横向滑动手势的敏感程度。0为迟钝 1为敏感
    public SwipeBackPage setSwipeSensitivity(float sensitivity) {
    mSwipeBackLayout.setSensitivity(mActivity, sensitivity);
    return this;
    }

    // 底层阴影颜色
    public SwipeBackPage setScrimColor(int color) {
    mSwipeBackLayout.setScrimColor(color);
    return this;
    }

    // 触发关闭Activity百分比
    public SwipeBackPage setClosePercent(float percent) {
    mSwipeBackLayout.setScrollThreshold(percent);
    return this;
    }

    public SwipeBackPage setDisallowInterceptTouchEvent(boolean disallowIntercept) {
    mSwipeBackLayout.setDisallowInterceptTouchEvent(disallowIntercept);
    return this;
    }

    public SwipeBackPage addListener(SwipeListener listener) {
    mSwipeBackLayout.addSwipeListener(listener);
    return this;
    }

    public SwipeBackPage removeListener(SwipeListener listener) {
    mSwipeBackLayout.removeSwipeListener(listener);
    return this;
    }

    public SwipeBackLayout getSwipeBackLayout() {
    return mSwipeBackLayout;
    }

    public void scrollToFinishActivity() {
    mSwipeBackLayout.scrollToFinishActivity();
    }

}
`

package com.jude.swipbackhelper;

/**

  • Created by Mr.Jude on 2015/8/26.
    */
    public class RelateSlider implements SwipeListener {
    public SwipeBackPage curPage;
    private int offset = 500;

    public RelateSlider(SwipeBackPage curActivity) {
    this.curPage = curActivity;
    // curPage.addListener(this);
    }

    public void setOffset(int offset) {
    this.offset = offset;
    }

    public void setEnable(boolean enable) {
    if (enable)
    curPage.addListener(this);
    else
    curPage.removeListener(this);
    }

    @OverRide
    public void onScroll(float percent, int px) {
    SwipeBackPage page = SwipeBackHelper.getPrePage(curPage);
    if (page != null) {

     	// page.getSwipeBackLayout().setX(-offset * Math.max(1 -
     	// percent,0));
     	page.getSwipeBackLayout().setScrollX((int)(offset * Math.max(1 - percent, 0)));
     	if (percent == 0) {
     		page.getSwipeBackLayout().setScrollX(0);
     		// page.getSwipeBackLayout().setX(0);
     	}
     }
    

    }

    @OverRide
    public void onEdgeTouch() {

    }

    @OverRide
    public void onScrollToClose() {
    SwipeBackPage page = SwipeBackHelper.getPrePage(curPage);
    if (page != null)
    page.getSwipeBackLayout().setScrollX(0);
    }
    }

@Jude95
Copy link
Owner

Jude95 commented Dec 31, 2016

感谢提了这么多的建议,我尽力在这3天解决!新年快乐!

@Jude95
Copy link
Owner

Jude95 commented Jan 2, 2017

问题4能详细说说怎么复现吗?

@Jude95
Copy link
Owner

Jude95 commented Jan 4, 2017

... @Paul-KK

@Paul-KK
Copy link
Author

Paul-KK commented Jan 6, 2017

问题很简单就会出现啊,直接关闭滑动(设置为false)返回就会透明啊。onpostcreat里面的问题,以前没问题的

@Jude95
Copy link
Owner

Jude95 commented Jan 11, 2017

透明指的是什么,能放一张截图说明吗。
不好意思这几天考试...

@5ZSQ
Copy link

5ZSQ commented Jan 21, 2017

现在这个版本是已经修复了的还是依旧存在有上述问题呢?看了下code的提交记录,看来是没有fix了~ 不过也谢谢@Jude95~

@duanxinyuan
Copy link

关闭滑动返回的话必须要设置false,不然就会出现透明背景

@Jude95
Copy link
Owner

Jude95 commented Jan 31, 2017

@919317632 透明背景指的是什么?

@Jude95
Copy link
Owner

Jude95 commented Jan 31, 2017

@5ZSQ 问题1不应该我解决,问题2已解决但没发布新版本。3,4我不明白是什么问题。也没人告诉我期望是什么,表现是什么,如何复现问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants