android教程viewpager自动循环和手动循环
package com.imoyo.expert;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
public class ExActivity extends Activity {
ViewPager viewPager;
ArrayList<View> list;
ViewGroup main, group;
boolean cunhuan = false;
ImageView imageView;
ImageView[] imageViews;
private static int c_id = 0;
static int page_id = 1;
private Runnable switchTask = new Runnable() {
public void run() {
if (cunhuan) {
viewPager.setCurrentItem(page_id);
page_id++;
}
cunhuan=true;
Log.e("is_run", cunhuan+"");
mHandler.postDelayed(switchTask, 3000);
}
};
Handler mHandler = new Handler();
@Override
protected void onResume() {
super.onResume();
switchTask.run();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getView();
imageViews = new ImageView[list.size()];
ViewGroup main = (ViewGroup) inflater.inflate(R.layout.activity_main,
null);
ViewGroup group = (ViewGroup) main.findViewById(R.id.viewGroup);
viewPager = (ViewPager) main.findViewById(R.id.viewPager);
for (int i = 0; i < 5; i++) {
imageView = new ImageView(this);
imageView.setLayoutParams(new LayoutParams(12, 12));
imageViews[i] = imageView;
if (i == 0) {
imageViews[i].setBackgroundResource(R.drawable.img_blue_point);
} else {
imageViews[i].setBackgroundResource(R.drawable.img_white_point);
}
group.addView(imageView);
}
setContentView(main);
ViewPagerAdapter adapter = new ViewPagerAdapter(this, list);
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(listener);
viewPager.setCurrentItem(2);
}
public void getView() {
inflater = getLayoutInflater();
list = new ArrayList<View>();
list.add(inflater.inflate(R.layout.item4, null));
list.add(inflater.inflate(R.layout.item5, null));
list.add(inflater.inflate(R.layout.item1, null));
list.add(inflater.inflate(R.layout.item2, null));
list.add(inflater.inflate(R.layout.item3, null));
list.add(inflater.inflate(R.layout.item4, null));
list.add(inflater.inflate(R.layout.item5, null));
list.add(inflater.inflate(R.layout.item1, null));
list.add(inflater.inflate(R.layout.item2, null));
}
OnPageChangeListener listener = new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
if (arg0 == 0) {
viewPager.setCurrentItem(5, false);
page_id=5;
} else if (arg0 == 8) {
viewPager.setCurrentItem(3, false);
page_id=3;
}else{
page_id=arg0;
}
Log.e("arg", arg0 + "");
for (int i = 2; i < 7; i++) {
imageViews[i - 2]
.setBackgroundResource(R.drawable.img_white_point);
}
switch (arg0) {
case 7:
case 2:
imageViews[0]
.setBackgroundResource(R.drawable.img_blue_point);
break;
case 3:
case 8:
imageViews[1]
.setBackgroundResource(R.drawable.img_blue_point);
break;
case 4:
imageViews[2]
.setBackgroundResource(R.drawable.img_blue_point);
break;
case 0:
case 5:
imageViews[3]
.setBackgroundResource(R.drawable.img_blue_point);
break;
case 1:
case 6:
imageViews[4]
.setBackgroundResource(R.drawable.img_blue_point);
break;
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
};
private LayoutInflater inflater;
}
- Android使用ViewPager实现启动引导页
- Android开发实战之漂亮的ViewPager引导页
- Android控件ViewPager实现带有动画的引导页
- Android UI设计与开发之使用ViewPager实现欢迎引导页面
- Android UI设计与开发之ViewPager仿微信引导界面以及动画效果
- Android UI设计与开发之ViewPager介绍和简单实现引导界面
- Android利用ViewPager实现用户引导界面效果的方法
- Android利用ViewPager实现滑动广告板实例源码
- Android ViewPager相册横向移动的实现方法
- Android开发实现的ViewPager引导页功能(动态加载指示器)详解
相关文章
flutter showModalBottomSheet常用属性及说明
这篇文章主要介绍了flutter showModalBottomSheet常用属性及说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-09-09Android安装应用 INSTALL_FAILED_DEXOPT 问题及解决办法
这篇文章主要介绍了Android安装应用 INSTALL_FAILED_DEXOPT 解决办法,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-04-04Android通过记住密码功能学习数据存储类SharedPreferences详解及实例
这篇文章主要通过“记住密码”实例功能学习为大家介绍了Android数据存储类SharedPreferences,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-03-03
最新评论