布局
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.ViewPager android:id="@+id/vp_guide" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.ViewPager> <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始体验" android:layout_centerHorizontal="true" android:textColor="#f00" android:layout_alignParentBottom="true" android:layout_marginBottom="20dp" android:visibility="invisible" /> </RelativeLayout>
2. 具体逻辑代码
public class GuideActivity extends AppCompatActivity{ private ViewPager vp_guide; private List<ImageView> imageViews; private int[] images={R.drawable.guide_1, R.drawable.guide_2, R.drawable.guide_3}; private Button btn_start; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); vp_guide= (ViewPager) findViewById(R.id.vp_guide); btn_start= (Button) findViewById(R.id.btn_start); initData(); vp_guide.setAdapter(new VpAdapter()); vp_guide.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { if(position==imageViews.size()-1){ btn_start.setVisibility(View.VISIBLE); }else{ btn_start.setVisibility(View.INVISIBLE); } } @Override public void onPageScrollStateChanged(int state) { } }); btn_start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { GotoActivity.gotoActivity(GuideActivity.this,MainActivity.class); } }); } public void initData(){ imageViews=new ArrayList<>(); ImageView view; for (int i = 0; i <images.length ; i++) { view=new ImageView(this); view.setBackgroundResource(images[i]); imageViews.add(view); } } class VpAdapter extends PagerAdapter{ @Override public int getCount() { return imageViews.size(); } @Override public boolean isViewFromObject(View view, Object object) { return view==object; } @Override public Object instantiateItem(ViewGroup container, int position) { ImageView view=imageViews.get(position); container.addView(view); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } } }
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦