真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

ViewPager實(shí)現(xiàn)漂亮的引導(dǎo)頁(yè)

廢話就不多說了,直接上效果圖和代碼

創(chuàng)新互聯(lián)是專業(yè)的福建網(wǎng)站建設(shè)公司,福建接單;提供網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行福建網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

ViewPager實(shí)現(xiàn)漂亮的引導(dǎo)頁(yè)

ViewPager實(shí)現(xiàn)漂亮的引導(dǎo)頁(yè)

fry.Activity01

package fry;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import com.example.viewPager.R;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Activity01 extends Activity implements OnPageChangeListener,OnClickListener{
 private ViewPager viewPager;
 private List views;//用來存放放進(jìn)ViewPager里面的ImageView
 private int[] imageID;//
 private ImagePagerAdapter adapter;//適配器
 private LinearLayout linearLayout;
 private int currentPoint;//當(dāng)前被選中中頁(yè)面的下標(biāo)
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity01);
  initData();
  initView();
  
 }
 //初始化view
 void initView(){
  adapter=new ImagePagerAdapter(views);
  viewPager=(ViewPager) findViewById(R.id.viewPager);
  viewPager.setAdapter(adapter);
  linearLayout=(LinearLayout) findViewById(R.id.linearLayout);
  initPoint();
  viewPager.setOnPageChangeListener(this);
 }
 
 //初始化數(shù)據(jù)
 void initData(){
  //將圖片的id全部放到imageID集合中
  imageID=new int[]{R.drawable.guide1,R.drawable.guide2,R.drawable.guide3,R.drawable.guide4};
  views=new ArrayList();
  //給iamgeView設(shè)置LayoutParams參數(shù)
  LayoutParams layoutParams=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  for(int i:imageID){
   //不確定1
   ImageView imageView=new ImageView(this);
   imageView.setImageResource(i);
   imageView.setLayoutParams(layoutParams);
   views.add(imageView);
  }
  
  
 }
 
 /*
  * 初始化頁(yè)面下方的點(diǎn)
  */
 private void initPoint(){
  ImageView[] imageView=new ImageView[imageID.length]; 
  for(int i=0;i

fry.ImagePagerAdapter

package fry;

import java.util.ArrayList;
import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

public class ImagePagerAdapter extends PagerAdapter{

 private List views;
 
 
 
 public ImagePagerAdapter(List views) {
  this.views=views;
 }

 @Override
 public int getCount() {
  // TODO Auto-generated method stub
  return this.views.size();
 }
 /**
  * position是在viewPager中顯示圖片的位置
  * 我對(duì)應(yīng)的圖片放到對(duì)應(yīng)的位置就好了
  * instantiateItem和destroyItem是對(duì)應(yīng)的
  * 一個(gè)是創(chuàng)建item,一個(gè)是銷毀item
  */
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
  ((ViewPager)container).addView(views.get(position));
  return views.get(position);
 }

 @Override
 public boolean isViewFromObject(View arg0, Object arg1) {
  // TODO Auto-generated method stub
  return arg0==arg1;
 }

 @Override
 public void destroyItem(ViewGroup container, int position, Object object) {
  ((ViewPager)container).removeView(views.get(position));
 }

}

/viewPager/res/layout/activity01.xml

<?xml version="1.0" encoding="utf-8"?>


 
  
 
 
 
  
  
  
  
  
 



ViewPager實(shí)現(xiàn)漂亮的引導(dǎo)頁(yè)

1、多個(gè)控件(這里指小圓點(diǎn))可以用List來一起訪問

2、可用動(dòng)態(tài)的控件設(shè)置tag來區(qū)分控件

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


分享名稱:ViewPager實(shí)現(xiàn)漂亮的引導(dǎo)頁(yè)
當(dāng)前網(wǎng)址:http://weahome.cn/article/jpcjcg.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部