android中无限循环滑动的gallery实例
来源:互联网 发布:ps读取复合数据怎么办 编辑:程序博客网 时间:2024/04/30 10:18
1.点击图片有变暗的效果,使用imageview.setAlpha(),并且添加ontouchListener
1 public void init() { 2 dots = new ImageView[len]; 3 for (int j = 0; j < len; j++) { 4 // 添加图片 5 final ImageView iv = new ImageView(this); 6 iv.setImageResource(res[j]); 7 views.add(iv); 8 iv.setOnTouchListener(new OnTouchListener() { 9 10 @Override11 public boolean onTouch(View v, MotionEvent event) {12 if (event.getAction() == MotionEvent.ACTION_DOWN) {13 iv.setAlpha(70);14 slideHandler.removeCallbacks(slideRun);15 }16 return false;17 }18 });19 // 添加索引20 ImageView imageView = new ImageView(this);21 imageView.setLayoutParams(new LayoutParams(15, 15));22 dots[j] = imageView;23 TextView tv = new TextView(this);24 tv.setText(" ");25 if (j == 0) {26 // 默认进入程序后第一张图片被选中;27 dots[j].setBackgroundResource(R.drawable.yst_i_pageon);28 } else {29 dots[j].setBackgroundResource(R.drawable.yst_i_pageoff);30 }31 32 layout_point.addView(tv);33 layout_point.addView(imageView);34 }35 gallery.setAdapter(new ImageAdapter());36 gallery.setSelection((Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2)37 % len);38 gallery.setOnItemSelectedListener(selectListener);39 ((MyGallery) gallery).setViews(views);40 // TODO 定时滑动41 startSlide();42 }
2.无限滑动,自定义adapter,设置count为最大值,图片总数循环从0到图片的总长度
View Code
3.自动滑动,自定义gallery,重写onFling方法,触摸时,停止滑动,弹起时继续滑动
View Code
下面贴出完整代码:
布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/background_light" tools:context=".MainActivity" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:orientation="vertical" > <com.allen.gallery.MyGallery android:id="@+id/mygallery" android:layout_width="fill_parent" android:layout_height="160dp" android:fadingEdge="horizontal|vertical" android:fadingEdgeLength="20dp" /> <LinearLayout android:id="@+id/layout_dots" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" > </LinearLayout> </LinearLayout></RelativeLayout>
2.完整的实现代码:
点击我
下载就不用了吧。。。
© Copyright by allen
http://www.cnblogs.com/Jaylong/archive/2013/07/03/3168984.html
0 0
- android中无限循环滑动的gallery实例
- Android Gallery无限循环
- Android的gallery实现无限循环和降低选择频率
- Android的gallery实现无限循环和降低选择频率
- Android利用Gallery制作无限循环的菜单
- Android Gallery 3张图无限循环 左右滑动都有效
- Android Gallery 3张图无限循环 左右滑动都有效
- Android进阶2之Gallery无限循环
- Android进阶2之Gallery无限循环
- Android进阶2之Gallery无限循环
- android viewpager 无限循环实现gallery 效果
- 实现gallery无限循环
- Gallery无限循环
- android之滑动悬浮tab&无限循环的viewPager
- Gallery循环滑动原理
- Gallery循环滑动
- android 中画廊Gallery的单页滑动
- Android ViewPager 实现无限循环滑动
- 放荡青春,我们没有谁对谁错
- 1.图层树 ---iOS-Core-Animation-Advanced-Techniques
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码
- Singleton模式的各种实现方式。
- C++实现生成均匀分布的数字
- android中无限循环滑动的gallery实例
- android app小白试水2-添加图片和文字滚动条
- IOS8中屏幕旋转问题解决
- E语言
- MFC改变static text颜色和内容及字体大小
- 【AllJoyn框架-07】Linux平台下用eclipse c++ 编译AllJoyn程序
- Linux编程基础——GDB(入门)
- C#发送http请求
- Hdu 2476 String painter(区间dp)