oubowu/SlideBack

滑动到某个位置的时候停留闪回去

JakeWoki opened this issue · 11 comments

demo没有这个问题,我在项目里用的时候出现,一直滑就不会出现,这个问题要怎么查?

贴log看看 这么神奇

打印哪里的log?

哦 明白你的意思了 是它滑动到某个位置停留 然后它自己回到原位吗?

是的,但是我用demo没有这个问题

这我也没发解决啊。。。。

可能是哪里出问题呢?我打印log看看

@oubowu
原来是轮播影响了。用的是BGABanner-Android。有轮播的页面是不滑动的,下一个页面才滑动。滑回去轮播的页面的过程中,在某个位置的时候停留会闪回去,这种情况怎么处理呢?

能发个简单的demo我试一下么?

build.gradle的增加
compile 'cn.bingoogolapple:bga-banner:2.1.5@aar'
compile 'com.github.bumptech.glide:glide:3.7.0'

content_main.xml改为

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/content_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.oubowu.slideback.demo.MainActivity"
    tools:showIn="@layout/activity_main">


    <cn.bingoogolapple.bgabanner.BGABanner
        android:id="@+id/banner"
        android:layout_width="match_parent"
        android:layout_height="163dp"
        app:banner_pointAutoPlayAble="true"
        app:banner_pointAutoPlayInterval="3000"
        app:banner_pointContainerBackground="#44aaaaaa"
        app:banner_pointContainerLeftRightPadding="10dp"
        app:banner_pointTopBottomMargin="6dp"
        app:banner_indicatorGravity="bottom|center_horizontal"
        app:banner_pageChangeDuration="800"
        app:banner_tipTextSize="10sp"
        app:banner_tipTextColor="@android:color/white"
        app:banner_pointDrawable="@drawable/bga_banner_selector_point_solid"
        app:banner_transitionEffect="accordion"/>

    <Button
        android:onClick="jump"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:foreground="?attr/selectableItemBackground"
        android:text="跳转侧滑页面"/>

    <Button
        android:onClick="jumpScroll"
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginBottom="40dp"
        android:foreground="?attr/selectableItemBackground"
        android:text="跳转带有滑动控件的页面"/>

</RelativeLayout>

MainActivity改为:

public class MainActivity extends AppCompatActivity implements BGABanner.Delegate<ImageView, String>, BGABanner.Adapter<ImageView, String>{

    BGABanner banner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        banner = (BGABanner) findViewById(R.id.banner);
        test();
    }

    private void test() {
        banner.setAdapter(MainActivity.this);
        List<String> imgs = new ArrayList<>();
        List<String> tips = new ArrayList<>();
        imgs.add("http://pic89.huitu.com/res/20161109/16517_20161109155832329050_1.jpg");
        imgs.add("http://pic89.huitu.com/res/20161105/1050513_20161105161149859020_1.jpg");
        tips.add("dddd");
        tips.add("fffffffff");
        banner.setData(imgs, tips);
    }

    @Override
    public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {

    }

    @Override
    public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
        Glide.with(itemView.getContext())
                .load(model)
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher)
                .dontAnimate()
                .centerCrop()
                .into(itemView);
    }

    @Override
    protected void onPause() {
        super.onPause();
        banner.stopAutoPlay();
    }

    public void jump(View view) {
        startActivity(new Intent(this, SecondActivity.class));
        overridePendingTransition(R.anim.anim_slide_in, R.anim.anim_none);
    }

    public void jumpScroll(View view) {
        startActivity(new Intent(this, ScrollActivity.class));
        overridePendingTransition(R.anim.anim_slide_in, R.anim.anim_none);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.anim_none, R.anim.anim_slide_out);
    }

}

这样就可以测出来了

原因我大致清楚了,因为侧滑的时候会把上个页面的View添加到侧滑布局中,然后banner.stopAutoPlay();这个没有停止轮播,需要使用banner.setAutoPlayAble(false);
因为在轮播的时候估计是布局重新layout了,导致重新调整了整个布局;
所以解决方法就是在onPause时调用banner.setAutoPlayAble(false)
onResume时调用banner.setAutoPlayAble(true)即可
@JakeWoki

多谢帮忙