import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
/**
* Created by lenovo on 2018/4/12.
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
private ViewPager vp;
private ArrayList<ImageView> list;
private ImageView aaa;
private ImageView bbb;
private ImageView ccc;
private ImageView lian;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
handler.sendEmptyMessageDelayed(0,1000);
}
private void initView() {
vp = (ViewPager) findViewById(R.id.vp);
list = new ArrayList<ImageView>();
int[] ints = new int[]{R.mipmap.aaa, R.mipmap.bbb, R.mipmap.ccc,R.mipmap.lian,R.mipmap.mish};
for (int i = 0; i < ints.length; i++) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(ints[i]);
list.add(imageView);
}
vp.setAdapter(new Adapter(list));
vp.setOnPageChangeListener(this);
}
@SuppressLint("HandlerLeak")
Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
int nowPage =vp.getCurrentItem();
int nextpage = nowPage+1 == list.size() ? 0:nowPage+1;
vp.setCurrentItem(nextpage);
if(nowPage+1==list.size()){
Intent intent = new Intent(MainActivity.this, SencodActivity.class);
MainActivity.this.startActivity(intent);
return;
}
sendEmptyMessageDelayed(0,1000);
}
};
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
}
*/
public class Adapter extends PagerAdapter{
ArrayList<ImageView> list;
public Adapter(ArrayList<ImageView> list) {
this.list=list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(list.get(position));
return list.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(list.get(position));
}
}
//引导页加点
//for (int i = 0; i < mList.size(); i++) {
// RadioButton button = new RadioButton(this);
// button.setId(i);
// button.setButtonDrawable(R.drawable.radiobutton_selector);
// if (i == 0) {
// button.setChecked(true);
// }
// mRadioGroup.addView(button);
// }
// adapter.notifyDataSetChanged();
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
/**
* Created by lenovo on 2018/4/12.
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
private ViewPager vp;
private ArrayList<ImageView> list;
private ImageView aaa;
private ImageView bbb;
private ImageView ccc;
private ImageView lian;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
handler.sendEmptyMessageDelayed(0,1000);
}
private void initView() {
vp = (ViewPager) findViewById(R.id.vp);
list = new ArrayList<ImageView>();
int[] ints = new int[]{R.mipmap.aaa, R.mipmap.bbb, R.mipmap.ccc,R.mipmap.lian,R.mipmap.mish};
for (int i = 0; i < ints.length; i++) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(ints[i]);
list.add(imageView);
}
vp.setAdapter(new Adapter(list));
vp.setOnPageChangeListener(this);
}
@SuppressLint("HandlerLeak")
Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
int nowPage =vp.getCurrentItem();
int nextpage = nowPage+1 == list.size() ? 0:nowPage+1;
vp.setCurrentItem(nextpage);
if(nowPage+1==list.size()){
Intent intent = new Intent(MainActivity.this, SencodActivity.class);
MainActivity.this.startActivity(intent);
return;
}
sendEmptyMessageDelayed(0,1000);
}
};
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
}
*/
public class Adapter extends PagerAdapter{
ArrayList<ImageView> list;
public Adapter(ArrayList<ImageView> list) {
this.list=list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(list.get(position));
return list.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(list.get(position));
}
}
//引导页加点
//for (int i = 0; i < mList.size(); i++) {
// RadioButton button = new RadioButton(this);
// button.setId(i);
// button.setButtonDrawable(R.drawable.radiobutton_selector);
// if (i == 0) {
// button.setChecked(true);
// }
// mRadioGroup.addView(button);
// }
// adapter.notifyDataSetChanged();