ImageSwitcher自定意效果+定时切换图片
Activity实现
1 import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView; import android.widget.Gallery.LayoutParams;
import android.widget.Toast;
import android.widget.ViewSwitcher.ViewFactory; public class Switcher extends Activity implements
ViewFactory {
private ImageSwitcher is;
private int Iindex=0;
private Gallery gallery;
/**
* 按下点的X坐标
*/
private float downX;
private int DuringTime=10000; private Integer[] mThumbIds = {R.drawable.a,R.drawable.b, R.drawable.c,
R.drawable.d,R.drawable.e, R.drawable.f, R.drawable.g}; private Integer[] mImageIds ={R.drawable.a,R.drawable.b, R.drawable.c,
R.drawable.d,R.drawable.e, R.drawable.f, R.drawable.g}; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.switcher); is = (ImageSwitcher) findViewById(R.id.switcher);
is.setFactory(this); //is.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_bottom_in));//渐入效果
is.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left));//系统提供渐变效果
is.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right));//渐出效果
//定时执行图片切换
is.postDelayed(new Runnable() {
public void run() {
if(Iindex==mImageIds.length-1){
Iindex=0;
}else{
Iindex++;
}
is.setImageResource(mImageIds[Iindex]);
is.postDelayed(this, DuringTime);
}
}, DuringTime); } @Override
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
i.setImageResource(mImageIds[Iindex]);
i.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:{
//手指按下的X坐标
downX = event.getX();
break;
}
case MotionEvent.ACTION_UP:{
float lastX = event.getX();
//抬起的时候的X坐标大于按下的时候就显示上一张图片
if(lastX > downX){
if(Iindex==0){
Iindex=mImageIds.length-1;
}else{
Iindex--;
}
is.setImageResource(mImageIds[Iindex]);
}else if(lastX < downX){
if(Iindex==mImageIds.length-1){
Iindex=0;
}else{
Iindex++;
}
is.setImageResource(mImageIds[Iindex]);
}
} break;
}
return true;
} });
//点击事件换图
/* i.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(Iindex==mImageIds.length-1){
Iindex=0;
}else{
Iindex++;
}
is.setImageResource(mImageIds[Iindex]);
//sm("you click this picture");
}
});*/
return i;
} private void sm(String mes){
Toast.makeText(this,mes,Toast.LENGTH_SHORT).show();
}
}
布局代码
1 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <ImageSwitcher android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
</RelativeLayout>
特效定义
<?xml version="1.0" encoding="utf-8"?>
<!-- 上下滑入式 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" > <!--<translate
android:duration="200"
android:fromYDelta="100%p"
android:toYDelta="0"
/>-->
<scale
android:interpolator= "@android:anim/decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:duration="1000"
android:repeatCount="1"
android:repeatMode="reverse"
/>
</set>
ImageSwitcher自定意效果+定时切换图片的更多相关文章
- javascript设计模式实践之职责链--具有百叶窗切换图片效果的JQuery插件(三)
在上一篇<javascript设计模式实践之模板方法--具有百叶窗切换图片效果的JQuery插件(二)>里,通过采用模板方法模式完成了切换效果对象的构建编写. 接下来就是完成各效果对象的调 ...
- javascript设计模式实践之模板方法--具有百叶窗切换图片效果的JQuery插件(二)
在上一篇<javascript设计模式实践之迭代器--具有百叶窗切换图片效果的JQuery插件(一)>里,通过采用迭代器模式完成了各初始化函数的定义和调用. 接下来就要完成各个切换效果的编 ...
- javascript设计模式实践之迭代器--具有百叶窗切换图片效果的JQuery插件(一)
类似于幻灯片的切换效果,有时需要在网页中完成一些图片的自动切换效果,比如广告,宣传,产品介绍之类的,那么单纯的切就没意思了,需要在切换的时候通过一些效果使得切换生动些. 比较常用之一的就是窗帘切换了. ...
- Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片
Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片 自定义ADPager 自定义水平滚动的ScrollView效仿ViewPager 当遇到要在Vie ...
- jQuery演示10种不同的切换图片列表动画效果
经常用到的图片插件演示jQuery十种不同的切换图片列表动画效果 在线演示 下载地址 实例代码 <!DOCTYPE html> <html lang="en" c ...
- jQuery演示10种不同的切换图片列表动画效果以及tab动画演示 2
很常用的一款特效纯CSS完成tab实现5种不同切换对应内容效果 实例预览 下载地址 实例代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...
- Core Animation一些Demo总结 (动态切换图片、大转盘、图片折叠、进度条等动画效果)
前一篇总结了Core Animation的一些基础知识,这一篇主要是Core Animation 的一些应用,涉及到CAShapeLayer.CAReplicatorLayer等图层的知识. 先看效果 ...
- CCSprite: fade 效果切换图片
//CCSprite+Animation.h #import "CCSprite.h" @interface CCSprite (Animation) + (void)fadeWi ...
- javascript---简介的切换图片效果。
<!--切换图片--> <img src="img/9.gif" alt="" id="img"> <butt ...
随机推荐
- bootstrap按钮组
种类 -a, input , button 块级 btn-block 按钮组 btn-group btn-group-justified btn-group-vertical </div ...
- Java文件读写操作指定编码方式防乱码
读文件:BufferedReader 从字符输入流中读取文本,缓冲各个字符,从而提供字符.数组和行的高效读取. 可以指定缓冲区的大小,或者可使用默认的大小.大多数情况下,默认值就足够大了. 通常,Re ...
- c#缓存 笔记
1:缓存. 你需要了解大数据高并发的瓶颈在哪里,一般都是数据库层面的,机械硬盘承载不起非常快速的读写操作,cpu承载不起大量的逻辑运算,所以最基本的解决思路就是:1.换固态硬盘加快硬盘的读写效率.2. ...
- Angular中使用Rainbow
在使用js类库和框架的时候,大家都习惯于编写自己的使用示例,如果能将示例中的html,js和css 进行展示, 并进行高亮显示,效果会很棒,例如在html高亮显示jquery代码 上面的示例是使用ra ...
- google 语音api
mdeia.Source = new Uri("http://translate.google.cn/translate_tts?ie=UTF-8&q=你好&tl=zh-CN ...
- ABAP 单位转换函数
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE' EXPORTING input = wa_all-btg ...
- XP共享连接数限制
- JPA查询语句(转载)
JPQL就是一种查询语言,具有与SQL 相类似的特征,JPQL是完全面向对象的,具备继承.多态和关联等特性,和hibernate HQL很相似. 查询语句的参数 JPQL语句支持两种方式的参数定义 ...
- va_list使用
http://www.programfan.com/blog/article.asp?id=41937
- 转载_虚拟机下LInux(终端)配置网络的方法
出自: http://www.360doc.com/content/14/1027/11/17496895_420258403.shtml 对文章的重点进行剪贴,方便查看. 这几天在虚拟机vmware ...