public class GuideActivity extends AppCompatActivity {
private ViewPager vp;
private List<View> pages = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guide);
vp = findViewById(R.id.guide_vp);
initData();
vp.setAdapter(new MyAdapter());
}
private void initData() {
View v1 = View.inflate(this, R.layout.guide1, null);
pages.add(v1);
View v2 = View.inflate(this, R.layout.guide2, null);
pages.add(v2);
Button btn = v2.findViewById(R.id.guide_but);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(GuideActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
});
}
class MyAdapter extends PagerAdapter{
@Override
public int getCount() {
return pages.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(pages.get(position));
return pages.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View)object);
}
}
}
引导页面
最新推荐文章于 2022-10-13 21:51:59 发布