以47度滑动Swip​​eListView:以编程方式滑动第一个项目 [英] SwipeListView by 47degree: swipe first item programmatically

查看:38
本文介绍了以47度滑动Swip​​eListView:以编程方式滑动第一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Activity 启动,向用户显示 SwipeListView 是可滑动的.

I would like to swipe the first item on the SwipeListView on Activity start up to show the user that the SwipeListView is swipe-able.

如何使用此UI元素以编程方式执行此操作?

How can I perform this action programmatically with this UI element?

我尝试使用

swipeListView.openAnimate(position)

这是答案中提出的,但是出于某种原因,即使在我用数据项填充适配器之后……当我调试并到达此代码段时,swipeListView也看不到其中的项,并失败, NullPointerException .

that was proposed here in the answer, but for some reason even after I populate the adapter with data-items... when I debug and reach this code section the swipeListView doesn't see item in it, and fails with NullPointerException.

好吧,我意识到适配器中没有任何项的原因是因为尚未在 onCreate 中创建它,所以我将这段代码移到了方法上:

Well, I realized that the reason there were no items in the adapter because it's not yet created in onCreate, so I moved this code to method:

public void onWindowFocusChanged(boolean hasFocus){}

我的活动,现在可以运行,但是在 SwipeListView 库的以下方法上仍然失败:

of my activity, now it runs but still fails on the following method of the SwipeListView library:

 private void resetCell() {
    if (downPosition != ListView.INVALID_POSITION) {
        if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
            backView.setVisibility(View.VISIBLE);
        }
        frontView.setClickable(opened.get(downPosition));
        frontView.setLongClickable(opened.get(downPosition));
        frontView = null;
        backView = null;
        downPosition = ListView.INVALID_POSITION;
    }
}

这样做的原因是,当此方法运行时,永远不会设置 frontView 对象,而将其设置为null.

The reason for this is that when this method is running the frontView object is never set and those it null.

推荐答案

我实际上已经去过并只是为Showcase实例在库中重新创建了使用的动画,所以我所做的是:

I have actually went and recreated the used animation in the library just for the instance of the Showcase, so what I did was:

private void generateRevealAnimate(final View view) {
    animate(view)
    .translationX(-520)
    .setDuration(500)
    .setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {}
    }); 
}

private void generateCloseAnimate(final View view) {
    animate(view)
    .translationX(0)
    .setDuration(500)
    .setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {}
    });
}

然后在所需的视图上一个接一个地运行它们:

And then just run them one after another on the desired view:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() 
    {
        generateRevealAnimate(firstFrontView); 
        handler.postDelayed(new Runnable() {
            @Override
            public void run()
            {
                generateCloseAnimate(firstFrontView);  
            }
        }, 1400);
    }
}, 1400);                 

这篇关于以47度滑动Swip​​eListView:以编程方式滑动第一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆