• ImageSwitcher 右向左滑动的实现方式


    ImageSwitcher is;
    ...
    is.setInAnimation(this, android.R.anim.slide_in_left);
    is.setOutAnimation(this, android.R.anim.slide_out_right);

    上面实现了从左向右滑动的效果,可是反过来,从右向左滑动怎么实现呢?

    默认情况下 android.R.anim.slide_in_right 和 android.R.anim.slide_out_left是私有的,也就是说通过.属性是找不到的.

    解决办法:slide_in_right和slide_out_left这两个xml都可以在sdk里找到的,修改后作为自己的资源调用就好了

    platforms\android-10\data\res\anim\下找到下面两个xml文件.

    slide_in_right

    slide_out_left

    最后放到项目 res->anim下面

    imgSwitcher.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub

                    if (event.getAction() == MotionEvent.ACTION_DOWN) {

                        downX = (intevent.getX(); // 取得按下时的坐标

                        Log.i("event.getX()"" downX " + downX);
                        return true;
                    } else if (event.getAction() == MotionEvent.ACTION_UP) {

                        upX = (intevent.getX(); // 取得松开时的坐标

                        Log.i("event.getX()"" upX " + downX);

                        // 从左拖到右,即看前一张
                        if (upX - downX > 100) {

                            imgSwitcher.setInAnimation(AnimationUtils
                                    .loadAnimation(firstActivity.this,
                                            android.R.anim.slide_in_left));
                            imgSwitcher.setOutAnimation(AnimationUtils
                                    .loadAnimation(firstActivity.this,
                                            android.R.anim.slide_out_right));
                            curIndex--;

                            if (curIndex < 0) {
                                curIndex = 5;
                            }

                            imgSwitcher.setImageResource(IMAGE_LIST[curIndex]);
                            firstActivity.this.switchTitle(curIndex);

                        } else if (downX - upX > 100) { // 从右拖到左,即看后一张

                            imgSwitcher.setInAnimation(AnimationUtils
                                    .loadAnimation(firstActivity.this,
                                            R.anim.slide_out_left));
                            imgSwitcher.setOutAnimation(AnimationUtils
                                    .loadAnimation(firstActivity.this,
                                            R.anim.slide_in_right));
                            curIndex++;
                            if (curIndex > 5) {
                                curIndex = 0;
                            }
                            imgSwitcher.setImageResource(IMAGE_LIST[curIndex]);
                            firstActivity.this.switchTitle(curIndex);
                        }
                        return true;
                    }
                    return false;
                }
            });
  • 相关阅读:
    .NET Core 之 MSBuild 介绍
    棒!使用.NET Core构建3D游戏引擎
    在ASP.NET Core MVC中构建简单 Web Api
    TypeScript 中的 SOLID 原则
    《C# 并发编程 · 经典实例》读书笔记
    ASP.NET Core 中的那些认证中间件及一些重要知识点
    消息队列 Kafka 的基本知识及 .NET Core 客户端
    【数列区间询问中的分块思想】
    2013 Multi-University Training Contest 8
    2013 Multi-University Training Contest 7
  • 原文地址:https://www.cnblogs.com/yourancao520/p/2417498.html
Copyright © 2020-2023  润新知