• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
jetereting
博客园    首页    新随笔    联系   管理    订阅  订阅

引导页

布局文件:来个铺满的ViewPager: 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#33ffffff"
  tools:context=".MainActivity">

  <android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/viewPage"/>

</RelativeLayout>

java文件:为ViewPager加个适配器: 

int imgIds[]={R.drawable.yindao21,R.drawable.yindao22,R.drawable.yindao23,R.drawable.yindao24};

SharedPreferences openTimes=getSharedPreferences("openTimes",0);

if(openTimes.getInt("times",0)==1){
  startActivity(new Intent().setClass(getApplicationContext(),Index.class));
  /**
  * 从主页返回后直接退出
  */
  finish();
}

ViewPager viewPager.setAdapter(new PagerAdapter() {
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    LinearLayout linearLayout=new LinearLayout(getApplicationContext());
    Button button=new Button(getApplicationContext());
    button.setText("点击进入");
    button.setBackgroundColor(Color.parseColor("#6b54f36b"));
    /**
    * 设置button的下边距
    */
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,                                    LinearLayout.LayoutParams.WRAP_CONTENT, 1);
    lp.setMargins(22,22,22,22);
    button.setLayoutParams(lp);

    linearLayout.setBackgroundResource(imgIds[position]);
    linearLayout.setGravity(Gravity.CENTER|Gravity.BOTTOM);
    /**
    * 如果是第4张引导图 在中下方加个按钮
    */
    if(position==3) {
      linearLayout.addView(button);
      button.setOnClickListener(new View.OnClickListener() {
      @Override
        public void onClick(View v) {
          startActivity(new Intent().setClass(getApplicationContext(),Index.class));
          finish();
        }
      });
     }
    container.addView(linearLayout);
    return linearLayout;
  }

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
}

@Override
public int getCount() {
  return imgIds.length;
}

@Override
public boolean isViewFromObject(View view, Object o) {
  return view==o;
}
});

 

posted @ 2015-04-24 19:55  jetereting  阅读(191)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3