android 滑动欢迎界面

import java.io.IOException;
import java.util.ArrayList;

import com.cimc.tank.xmlparser.Page;
import com.cimc.tank.xmlparser.XmlSettingParser;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
/**
 *
 * @author Administrator
 *
 */
public class FunctionShowActivity extends Activity
{

    private Page pageMenu;
    private String strBtnFunctionShow;
    ViewPager viewPager;  

    ArrayList<View> list;  
    ViewGroup main, group;  
    ImageView imageView;  
    ImageView[] imageViews;
    Button btnEnterShixin;

    @Override  

    public void onCreate(Bundle savedInstanceState)
    {  
        super.onCreate(savedInstanceState);  
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
        LayoutInflater inflater = getLayoutInflater();  
        Intent intent=getIntent();
        try{
            getParaFromXML();  
        }catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      
        list = new ArrayList<View>();  
        list.add(inflater.inflate(R.layout.function1, null));  
        list.add(inflater.inflate(R.layout.function2, null));  
        list.add(inflater.inflate(R.layout.function3, null));  
        list.add(inflater.inflate(R.layout.function4, null));  
        btnEnterShixin=(Button)list.get(list.size()-1).findViewById(R.id.function_enter_btn);
        btnEnterShixin.setVisibility(View.VISIBLE);
        
        if(intent.getIntExtra("ShowFrom", 0)==1)
        {
            btnEnterShixin.setText(strBtnFunctionShow);
            btnEnterShixin.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent =new Intent(FunctionShowActivity.this,LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
            });
        }
        else
        {
            btnEnterShixin.setText(strBtnFunctionShow);
            btnEnterShixin.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    // TODO Auto-generated method stub
                    finish();
                }
            });
        }

        imageViews = new ImageView[list.size()];  
        ViewGroup main = (ViewGroup) inflater.inflate(R.layout.function_show_activity, null);  

     // group是R.layou.main中的负责包裹小圆点的LinearLayout.  

        ViewGroup group = (ViewGroup) main.findViewById(R.id.viewGroup);  
        viewPager = (ViewPager) main.findViewById(R.id.viewPager);  
        for (int i = 0; i < list.size(); i++)
        {  
            imageView = new ImageView(FunctionShowActivity.this);  
            LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(10,10);
            lp.setMargins(10, 0, 10, 0);
            imageView.setLayoutParams(lp);  

            imageViews[i] = imageView;  
            if (i == 0)
            {  
                 // 默认进入程序后第一张图片被选中;  
                imageViews[i].setBackgroundResource(R.drawable.white_dot);  
            } else {  
                imageViews[i].setBackgroundResource(R.drawable.blue_dot);  
            }  
            group.addView(imageView);  
        }  
        setContentView(main);  
        viewPager.setAdapter(new MyAdapter());  
        viewPager.setOnPageChangeListener(new MyListener());  
    }  

    /**   
     * @Description:获取该界面属于该界面的所有配置信息    
     * @throws IOException
     */
    private void getParaFromXML() throws IOException
    {      
        pageMenu = XmlSettingParser.getInstance().getPageByStyle("settingStyle");        
        strBtnFunctionShow= pageMenu.getPageData().get(0).fieldCaption;
    }
    
/**
 * 自定义page容器
 * @author Administrator
 *
 */
    class MyAdapter extends PagerAdapter
    {  
        @Override  
        public int getCount()
        {  
            return list.size();  
        }  
        @Override  
        public boolean isViewFromObject(View arg0, Object arg1)
        {  
            return arg0 == arg1;  
        }  
        @Override  
        public int getItemPosition(Object object)
        {  
            // TODO Auto-generated method stub  
            return super.getItemPosition(object);  
        }  

        @Override  
        public void destroyItem(View arg0, int arg1, Object arg2)
        {  
            // TODO Auto-generated method stub  
            ((ViewPager) arg0).removeView(list.get(arg1));  
        }  

        @Override  
        public Object instantiateItem(View arg0, int arg1)
        {  
            // TODO Auto-generated method stub  
            ((ViewPager) arg0).addView(list.get(arg1));  
            return list.get(arg1);  
        }  

 

        @Override  
        public void restoreState(Parcelable arg0, ClassLoader arg1)
        {  
            // TODO Auto-generated method stub  
        }  

 
        @Override  
        public Parcelable saveState()
        {  
            // TODO Auto-generated method stub  
            return null;  
        }  
 
        @Override  
        public void startUpdate(View arg0)
        {  
            // TODO Auto-generated method stub  
        }  

        @Override  
        public void finishUpdate(View arg0)
        {  
            // TODO Auto-generated method stub  
        }  
    }  


    class MyListener implements OnPageChangeListener
    {  

        @Override  
        public void onPageScrollStateChanged(int arg0)
        {  
            // TODO Auto-generated method stub   
        }  

        @Override  
        public void onPageScrolled(int arg0, float arg1, int arg2)
        {  
            // TODO Auto-generated method stub  
        }  

        @Override  
        public void onPageSelected(int arg0)
        {  
            for (int i = 0; i < imageViews.length; i++)
            {  
                imageViews[arg0]  .setBackgroundResource(R.drawable.white_dot);  
                if (arg0 != i)
                {  
                    imageViews[i]  .setBackgroundResource(R.drawable.blue_dot);  
                }  
            }  
        }  
    }  



============================================================================================================


import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.lenovo.elec.R;

/**
 * 使用向导
 *
 * @author 
 *
 */
public class GuideActivity extends Activity {

 protected static final String TAG = "GuideActivity";
 ViewPager viewPager;
 ArrayList<View> list;
 ViewGroup main, group;
 ImageView imageView;
 ImageView[] imageViews;
 View view5;
 private Button guide_start;
 private Intent intent;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // 设置无标题
  this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  LayoutInflater inflater = getLayoutInflater();

  list = new ArrayList<View>();
  list.add(inflater.inflate(R.layout.guideitem1, null));
  list.add(inflater.inflate(R.layout.guideitem2, null));
  list.add(inflater.inflate(R.layout.guideitem3, null));
  list.add(inflater.inflate(R.layout.guideitem4, null));
  view5 = inflater.inflate(R.layout.guideitem5, null);
  list.add(view5);
  imageViews = new ImageView[list.size()];

  ViewGroup main = (ViewGroup) inflater.inflate(R.layout.guide, null);
  // group是R.layou.guide中的负责包裹小圆点的LinearLayout.
  ViewGroup group = (ViewGroup) main.findViewById(R.id.viewGroup);
  viewPager = (ViewPager) main.findViewById(R.id.viewPager);
  for (int i = 0; i < list.size(); i++) {
   imageView = new ImageView(this);
   imageView.setLayoutParams(new LayoutParams(30, 20));
   imageView.setPadding(15, 0, 15, 0);
   imageViews[i] = imageView;
   if (i == 0) {
    imageViews[i].setBackgroundResource(R.drawable.guide_dot_blue);
    // 默认进入程序后第一张图片被选中;
   } else {
    imageViews[i].setBackgroundResource(R.drawable.guide_dot_white);
   }
   group.addView(imageView);
  }
  setContentView(main);

  guide_start = (Button) view5.findViewById(R.id.guide_start);
  guide_start.setOnClickListener(new OnClickListener() {
   public void onClick(View v) {
    intent = new Intent(GuideActivity.this, CustomTabActivity.class);
    startActivity(intent);
    Toast.makeText(getApplicationContext(), "进入我的小屋", 0).show();
    finish();
   }
  });

  viewPager.setAdapter(new MyAdapter());
  viewPager.setOnPageChangeListener(new MyListener());

 }

 /**
  * 返回键退出
  */
 @Override
 public void onBackPressed() {

 }

 class MyAdapter extends PagerAdapter {

  @Override
  public int getCount() {
   return list.size();
  }

  @Override
  public boolean isViewFromObject(View arg0, Object arg1) {
   return arg0 == arg1;
  }

  @Override
  public int getItemPosition(Object object) {
   return super.getItemPosition(object);
  }

  @Override
  public void destroyItem(View arg0, int arg1, Object arg2) {
   ((ViewPager) arg0).removeView(list.get(arg1));
  }

  @Override
  public Object instantiateItem(View arg0, int arg1) {
   ((ViewPager) arg0).addView(list.get(arg1));
   return list.get(arg1);
  }

  @Override
  public void restoreState(Parcelable arg0, ClassLoader arg1) {

  }

  @Override
  public Parcelable saveState() {
   return null;
  }

  @Override
  public void startUpdate(View arg0) {

  }

  @Override
  public void finishUpdate(View arg0) {

  }
 }

 class MyListener implements OnPageChangeListener {

  public void onPageScrollStateChanged(int arg0) {

  }

  public void onPageScrolled(int arg0, float arg1, int arg2) {

  }

  public void onPageSelected(int arg0) {
   for (int i = 0; i < imageViews.length; i++) {
    imageViews[arg0].setBackgroundResource(R.drawable.guide_dot_blue);
    if (arg0 != i) {
     imageViews[i].setBackgroundResource(R.drawable.guide_dot_white);
    }
   }

  }

 }

}

你可能感兴趣的:(android 滑动欢迎界面)