资源简介
package com.example.viewpager;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends Activity
{
private int[] imgResIDs = new int[]
{ R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e };
private int[] radioButtonID = new int[]
{ R.id.radio0, R.id.radio1, R.id.radio2, R.id.radio3, R.id.radio4 };
private ViewPager pager;
private RadioGroup mGroup;
private ArrayList<View> items = new ArrayList<View>();
private Runnable runnable;
private int mCurrentItem = 0;
private int mItem;
private Runnable mPagerAction;
private boolean isFrist = true;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.tuijian_pager);
mGroup = (RadioGroup) findViewById(R.id.radioGroup1);
initAllItems();
pager.setAdapter(new PagerAdapter()
{
// 创建
@Override
public Object instantiateItem(View container, int position)
{
View layout = items.get(position % items.size());
pager.addView(layout);
return layout;
}
// 销毁
@Override
public void destroyItem(View container, int position, Object object)
{
View layout = items.get(position % items.size());
pager.removeView(layout);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1)
{
return arg0 == arg1;
}
@Override
public int getCount()
{
return imgResIDs.length;
}
});
pager.setOnPageChangeListener(new OnPageChangeListener()
{
@Override
public void onPageSelected(final int arg0)
{
mCurrentItem = arg0 % items.size();
pager.setCurrentItem(mCurrentItem);
mGroup.check(radioButtonID[mCurrentItem]);
items.get(arg0).findViewById(R.id.tuijian_header_img).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(MainActivity.this, arg0 "", 1000).show();
}
});
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0)
{
// TODO Auto-generated method stub
}
});
mPagerAction = new Runnable()
{
@Override
public void run()
{
if (mItem != 0)
{
if (isFrist == true)
{
mCurrentItem = 0;
isFrist = false;
}
else
{
if (mCurrentItem == items.size() - 1)
{
mCurrentItem = 0;
}
else
{
mCurrentItem ;
}
}
pager.setCurrentItem(mCurrentItem);
mGroup.check(radioButtonID[mCurrentItem]);
}
pager.postDelayed(mPagerAction, 2500);
}
};
pager.postDelayed(mPagerAction, 100);
}
private void initAllItems()
{
// 初始化Viewpager的所有item
for (int i = 0; i < imgResIDs.length; i )
{
items.add(initPagerItem(imgResIDs[i]));
}
mItem = items.size();
}
private View initPagerItem(int resID)
{
View layout1 = getLayoutInflater().inflate(R.layout.tuijian_header, null);
ImageView imageView1 = (ImageView) layout1.findViewById(R.id.tuijian_header_img);
imageView1.setImageResource(resID);
return layout1;
}
}
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends Activity
{
private int[] imgResIDs = new int[]
{ R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e };
private int[] radioButtonID = new int[]
{ R.id.radio0, R.id.radio1, R.id.radio2, R.id.radio3, R.id.radio4 };
private ViewPager pager;
private RadioGroup mGroup;
private ArrayList<View> items = new ArrayList<View>();
private Runnable runnable;
private int mCurrentItem = 0;
private int mItem;
private Runnable mPagerAction;
private boolean isFrist = true;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.tuijian_pager);
mGroup = (RadioGroup) findViewById(R.id.radioGroup1);
initAllItems();
pager.setAdapter(new PagerAdapter()
{
// 创建
@Override
public Object instantiateItem(View container, int position)
{
View layout = items.get(position % items.size());
pager.addView(layout);
return layout;
}
// 销毁
@Override
public void destroyItem(View container, int position, Object object)
{
View layout = items.get(position % items.size());
pager.removeView(layout);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1)
{
return arg0 == arg1;
}
@Override
public int getCount()
{
return imgResIDs.length;
}
});
pager.setOnPageChangeListener(new OnPageChangeListener()
{
@Override
public void onPageSelected(final int arg0)
{
mCurrentItem = arg0 % items.size();
pager.setCurrentItem(mCurrentItem);
mGroup.check(radioButtonID[mCurrentItem]);
items.get(arg0).findViewById(R.id.tuijian_header_img).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(MainActivity.this, arg0 "", 1000).show();
}
});
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0)
{
// TODO Auto-generated method stub
}
});
mPagerAction = new Runnable()
{
@Override
public void run()
{
if (mItem != 0)
{
if (isFrist == true)
{
mCurrentItem = 0;
isFrist = false;
}
else
{
if (mCurrentItem == items.size() - 1)
{
mCurrentItem = 0;
}
else
{
mCurrentItem ;
}
}
pager.setCurrentItem(mCurrentItem);
mGroup.check(radioButtonID[mCurrentItem]);
}
pager.postDelayed(mPagerAction, 2500);
}
};
pager.postDelayed(mPagerAction, 100);
}
private void initAllItems()
{
// 初始化Viewpager的所有item
for (int i = 0; i < imgResIDs.length; i )
{
items.add(initPagerItem(imgResIDs[i]));
}
mItem = items.size();
}
private View initPagerItem(int resID)
{
View layout1 = getLayoutInflater().inflate(R.layout.tuijian_header, null);
ImageView imageView1 = (ImageView) layout1.findViewById(R.id.tuijian_header_img);
imageView1.setImageResource(resID);
return layout1;
}
}
代码片段和文件信息
/** Automatically generated file. DO NOT MODIFY */
package com.example.viewpager;
public final class BuildConfig {
public final static boolean DEBUG = true;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 475 2014-06-12 13:52 viewpager\.classpath
文件 845 2014-06-12 13:51 viewpager\.project
文件 884 2014-06-12 13:52 viewpager\AndroidManifest.xm
文件 884 2014-06-12 16:08 viewpager\bin\AndroidManifest.xm
文件 351 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\BuildConfig.class
文件 1794 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\MainActivity$1.class
文件 1280 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\MainActivity$2$1.class
文件 2209 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\MainActivity$2.class
文件 1800 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\MainActivity$3.class
文件 3903 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\MainActivity.class
文件 640 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\MyViewPager.class
文件 1566 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$attr.class
文件 652 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$bool.class
文件 1472 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$color.class
文件 1276 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$dimen.class
文件 1036 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$drawable.class
文件 816 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$id.class
文件 694 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$integer.class
文件 450 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$layout.class
文件 397 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$menu.class
文件 481 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$string.class
文件 671 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$st
文件 3485 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R$st
文件 917 2014-06-17 11:44 viewpager\bin\classes\com\example\viewpager\R.class
文件 1569 2014-06-17 11:44 viewpager\bin\classes\com\viewpagerindicator\R$attr.class
文件 655 2014-06-17 11:44 viewpager\bin\classes\com\viewpagerindicator\R$bool.class
文件 1475 2014-06-17 11:44 viewpager\bin\classes\com\viewpagerindicator\R$color.class
文件 1181 2014-06-17 11:44 viewpager\bin\classes\com\viewpagerindicator\R$dimen.class
文件 740 2014-06-17 11:44 viewpager\bin\classes\com\viewpagerindicator\R$drawable.class
文件 516 2014-06-17 11:44 viewpager\bin\classes\com\viewpagerindicator\R$id.class
............此处省略91个文件信息
相关资源
- Android 页面中垂直滚动的公告条(An
- Android 高仿LOFTER
- Android代码-MaterialDesign风格的列表滚动
- JS实现图片轮播效果(绝对可用
- ScrolledComposite自动出现滚动条
- 很不错的marquee不间断滚动,调用数据
- Android仿iPhone滚动控件源码
- JAVA实验字符串的滚动
- android 滚动字幕跑马灯效果
- Android文字消息垂直轮播控件
- java实现一个滚动字幕的程序
- Android tab 栏居中滚动
- Java 滚动广告字幕
-
Java ap
plet中滚动广告字幕动画 - MFC缩略图滚动预览_VS2008
- 全屏轮播上线倒计时模板
- Java 循环滚动图片
- android 3D轮播
- android 数字滚动 wheel
- douBanList(滚动到底部加载新的,软缓
- 仿Iphone的滚动选择器
- unity 卡片椭圆方向滚动
- android 仿html table布局可横向 纵向滚动
- Android 明日首页轮播图(App 应用开发
- android 图片轮播
- 自定义滚动条
- 上下切换连续滚动的文字
- jQuery 图片轮播源码
- 很实用的图片从右到左滚动的jsp代码
- 安卓实现动态波浪滚动
评论
共有 条评论