博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ImageSwitcher 右向左滑动的实现方式
阅读量:4472 次
发布时间:2019-06-08

本文共 1780 字,大约阅读时间需要 5 分钟。

 

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 = (
int
event.getX(); 
//
 取得按下时的坐标
                    Log.i(
"
event.getX()
"
"
 downX 
" + downX);
                    
return 
true;
                } 
else 
if (
event.getAction() == MotionEvent.ACTION_UP) {
                    upX = (
int
event.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;
            }
        });

 

 

转载于:https://www.cnblogs.com/yourancao520/archive/2012/03/26/2417498.html

你可能感兴趣的文章
设计模式学习-每日一记(6.原型模式)
查看>>
LeetCode--018--四数之和(java)
查看>>
Redis消息队列
查看>>
电商网站架构设计
查看>>
http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
查看>>
WCF netTcp配置
查看>>
数据类型转换
查看>>
Nodejs学习笔记(2) 阻塞/非阻塞实例 与 Nodejs事件
查看>>
什么是FreeMaker
查看>>
设计模式学习笔记(总结篇:模式分类)
查看>>
TCP的三次握手/建立连接
查看>>
Python 教程阅读笔记(一):使用解释器
查看>>
运算符重载
查看>>
SDWebImage 新版接口使用方法
查看>>
android ListView详解
查看>>
软件工程 第一次作业
查看>>
Content Server HA搭建
查看>>
[leetCode]Linked List Cycle I+II
查看>>
leetcode中的python学习
查看>>
Zookeeper zkui-zookeeper图形化管理工具
查看>>