ViewPager的定時(shí)滾動(dòng),動(dòng)態(tài)加載數(shù)據(jù)

viewpager是用在滾動(dòng)中相對(duì)比較多的走孽,最近做一個(gè)定時(shí)滾動(dòng)顯示viewpager內(nèi)容念逞。

步驟:

一:在布局文件添加v4包下的viewpager:

android:id="@+id/main_viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_gravity="center">

二:獲取后臺(tái)數(shù)據(jù),現(xiàn)在就暫時(shí)自己造幾條數(shù)據(jù)创淡,并寫adapter內(nèi)容

//構(gòu)造list集合

list=newArrayList();

list.add(R.mipmap.image1);

list.add(R.mipmap.image2);

list.add(R.mipmap.image3);

//我這邊是顯示的viewpager的很多信息,包括圖片文字劳较,所以構(gòu)造view墓捻,在Java中寫布局代碼凸丸,

這個(gè)時(shí)候就需要我們構(gòu)造view环肘,privateListmList=new ArryList;

循化list集合數(shù)據(jù)腌零,創(chuàng)建頁(yè)面詳情,通過(guò)add方法加載到mList记舆,這樣adapter中就可以傳遞過(guò)去值了:

for(inti =0;i

rootlayout=newRelativeLayout(this);

rootlayout.setLayoutParams(newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT));

rootlayout.setId(0);

ImageView imageView =newImageView(this);

RelativeLayout.LayoutParams image_Params =newRelativeLayout.LayoutParams(

dip2px(250),dip2px(192));

image_Params.setMargins(dip2px(5),0,dip2px(5),dip2px(5));

imageView.setLayoutParams(image_Params);

imageView.setImageResource(list.get(i));

//Picasso.with(ViewPagersActivity.this).load(tsfbBeans.get(i).getBook_pic()).error(R.mipmap.image1).into(imageView);

imageView.setId(1);

//字體顏色

Resources resource = (Resources) getBaseContext().getResources();

ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.book_text);

TextView text_Name =newTextView(this);

RelativeLayout.LayoutParams text_Name_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_Name_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_Name_Params.addRule(RelativeLayout.ALIGN_TOP,imageView.getId());

text_Name_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_Name.setLayoutParams(text_Name_Params);

text_Name.setText("圖書描述:");

//text_Name.setText(tsfbBeans.get(i).getBook_name() + ":");

text_Name.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_Name.setTextColor(csl);

text_Name.setId(2);

TextView text_Email =newTextView(this);

RelativeLayout.LayoutParams text_Email_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_Email_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_Email_Params.addRule(RelativeLayout.BELOW,text_Name.getId());

text_Email_Params.setMargins(dip2px(10),dip2px(5),dip2px(10),0);

text_Email.setLayoutParams(text_Email_Params);

text_Email.setText("《詩(shī)經(jīng)》是中國(guó)古代詩(shī)歌開端摘能,最早的一部詩(shī)歌總集峻黍,收集了西周初年至春秋中葉(前11世紀(jì)至前6世紀(jì))的詩(shī)歌,共311篇黎侈,其中6篇為笙詩(shī),即只有標(biāo)題希太,沒有內(nèi)容亡脑,稱為笙詩(shī)六篇");

//text_Email.setText(tsfbBeans.get(i).getBook_description());

text_Email.setTextSize(TypedValue.COMPLEX_UNIT_SP,13);

text_Email.setId(3);

TextView text_author =newTextView(this);

RelativeLayout.LayoutParams text_author_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_author_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_author_Params.addRule(RelativeLayout.BELOW,text_Email.getId());

text_author_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_author.setLayoutParams(text_author_Params);

text_author.setText("圖書作者:");

//text_author.setText("圖書作者:" + tsfbBeans.get(i).getBook_author());

text_author.setTextColor(csl);

text_author.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_author.setId(4);

TextView text_place =newTextView(this);

RelativeLayout.LayoutParams text_place_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_place_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_place_Params.addRule(RelativeLayout.BELOW,text_author.getId());

text_place_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_place.setLayoutParams(text_place_Params);

text_place.setText("出版社:");

//text_place.setText("出版社:" + tsfbBeans.get(i).getBook_publishing());

text_place.setTextColor(csl);

text_place.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_place.setId(5);

TextView text_data =newTextView(this);

RelativeLayout.LayoutParams text_data_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_data_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_data_Params.addRule(RelativeLayout.BELOW,text_place.getId());

text_data_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_data.setLayoutParams(text_data_Params);

text_data.setText("出版日期:");

// text_data.setText("出版日期:" + tsfbBeans.get(i).getBook_publication_date());

text_data.setTextColor(csl);

text_data.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_data.setId(6);

TextView text_description_name =newTextView(this);

RelativeLayout.LayoutParams text_DescriptionName_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_DescriptionName_Params.addRule(RelativeLayout.BELOW,imageView.getId());

//text_Name_Params.addRule(RelativeLayout.ALIGN_TOP, imageView.getId());

text_DescriptionName_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_description_name.setLayoutParams(text_DescriptionName_Params);

text_description_name.setText("圖書簡(jiǎn)介:");

text_description_name.setTextColor(csl);

text_description_name.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_description_name.setId(7);

TextView text_description =newTextView(this);

RelativeLayout.LayoutParams text_Description_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_Description_Params.addRule(RelativeLayout.BELOW,text_description_name.getId());

//text_Name_Params.addRule(RelativeLayout.ALIGN_TOP, imageView.getId());

text_Description_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_description.setLayoutParams(text_Description_Params);

text_description.setText("111");

//text_description.setText(tsfbBeans.get(i).getBook_abstract());

text_description.setTextSize(TypedValue.COMPLEX_UNIT_SP,13);

text_description.setId(8);

rootlayout.addView(imageView,image_Params);

rootlayout.addView(text_Name,text_Name_Params);

rootlayout.addView(text_Email,text_Email_Params);

rootlayout.addView(text_description,text_Description_Params);

rootlayout.addView(text_author,text_author_Params);

rootlayout.addView(text_place,text_place_Params);

rootlayout.addView(text_data,text_data_Params);

rootlayout.addView(text_description_name,text_DescriptionName_Params);

//setContentView(rootlayout);

mList.add(rootlayout);

}

來(lái)講講adapter,基本寫法就行坑傅,但是注意的是在添加view的時(shí)候必須保證是一個(gè)view的parent喷斋,要不然報(bào)錯(cuò):

public classTTMyPagerAdaptersextendsPagerAdapter {

publicListlistViews=null;

publicTTestViewPagersActivitymContext;

publicTTMyPagerAdapters(List listViews,TTestViewPagersActivity mContext) {

this.listViews= listViews;

this.mContext= mContext;

Share.d("listviews"+ listViews.size());

}

@Override

public intgetCount() {

returnInteger.MAX_VALUE;

}

@Override

public booleanisViewFromObject(View arg0,Object arg1) {

returnarg0 == arg1;

}

@Override

public voiddestroyItem(View container, intposition,Object object) {

Share.d("TipsPagerAdapter,destroyItem is called? "+ position);

((ViewPager) container).removeView(listViews.get(position %listViews.size()));

}

@Override

publicCharSequencegetPageTitle(intposition) {

return super.getPageTitle(position);

}

@Override

publicObjectinstantiateItem(View container, intposition) {

Share.d("TipsPagerAdapter, instantiateItem is called "+ position);

try{

((ViewPager) container).addView(

listViews.get(position %listViews.size()),0);

}catch(Exception e) {

}

// ((ViewPager) container).addView(listViews.get(position);

// return listViews.get(position);

Share.d("instantiateItem>>>>>>"+ position %listViews.size());

returnlistViews.get(position %listViews.size());

}

}

好了現(xiàn)在就是直接setadapter就行了枉证,然后寫個(gè)線程循環(huán)跳

adapter=newTTMyPagerAdapters(mList, this);

mPager.setAdapter(adapter);

mPager.setCurrentItem(position);

position是初始滑動(dòng)值,凈量設(shè)置越大越好毡鉴,一般滑不到頭

private voidinitAdapter() {

Share.d("mlist"+mList.size());

//

//TODO Auto-generated method stub

//TODO Auto-generated catch block

change=newThread(newRunnable() {

@Override

public voidrun() {

//TODO Auto-generated method stub

while(true) {

handler.sendEmptyMessage(0);

try{

Thread.sleep(5000);

}catch(InterruptedException e) {

//TODO Auto-generated catch block

e.printStackTrace();

}

}

}

});

change.start();

}

@SuppressLint("HandlerLeak")

privateHandlerhandler=newHandler() {

@Override

public voidhandleMessage(Message msg) {

super.handleMessage(msg);

switch(msg.what) {

case0:

position++;

mPager.setCurrentItem(position);

break;

default:

break;

}

}

};

好了現(xiàn)在可沒有結(jié)束猪瞬,你會(huì)發(fā)現(xiàn)list的集合數(shù)小于3的時(shí)候又空白頁(yè)出現(xiàn)陈瘦,但是一張的時(shí)候你又不想讓他滾動(dòng)潮售,怎么辦酥诽?主要是數(shù)據(jù)太短銷毀的時(shí)候有bug肮帐,要是list多了那就無(wú)所謂了,所以怎么辦呢托修?其中一個(gè)辦法睦刃,可以把小于3的list通過(guò)一個(gè)for循環(huán)構(gòu)造出大于他不就OK了仗处,所以那就開干婆誓,循環(huán)添加吧也颤!總結(jié)這個(gè)問(wèn)題就是數(shù)據(jù)一條的時(shí)候翅娶,和2/3條的時(shí)候和多于3條的時(shí)候情況不一樣好唯,分別處理骑篙,我的做法是先在判斷集合以2為界限判斷森书,實(shí)驗(yàn)多次就是2的時(shí)候容易空白凛膏,所以區(qū)分是2和不是的時(shí)候猖毫,是2的話讓他for循環(huán)添加兩次進(jìn)去數(shù)據(jù)變成4就好了,不是2的正常執(zhí)行趁蕊,但是不是2的里邊包括1個(gè)的時(shí)候介衔,那么就在setadapter的時(shí)候處理,區(qū)分新的list是1還是大于3的骂因,這樣問(wèn)題就解決了炎咖,下邊附上全部代碼!

packagecom.example.administrator.student.ui;

importandroid.annotation.SuppressLint;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.content.res.ColorStateList;

importandroid.content.res.Resources;

importandroid.os.Bundle;

importandroid.os.Handler;

importandroid.os.Message;

importandroid.support.v4.view.ViewPager;

importandroid.util.TypedValue;

importandroid.view.MotionEvent;

importandroid.view.View;

importandroid.widget.ImageView;

importandroid.widget.RelativeLayout;

importandroid.widget.TextView;

importcom.example.administrator.student.R;

importcom.example.administrator.student.adapter.TMyPagerAdapters;

importcom.example.administrator.student.adapter.TTMyPagerAdapters;

importcom.example.administrator.student.bean.Main_Data;

importcom.example.administrator.student.utils.Share;

importjava.util.ArrayList;

importjava.util.List;

/**

* Created by Administrator on 2017/10/16.

*/

public classTTestViewPagersActivityextendsActivity {

privateViewPagermPager;

privateListmList;

privateListtsfbBeans=newArrayList();

privateTTMyPagerAdaptersadapter;

privateListlist;

private intposition=50000;

privateThreadchange;

privateRelativeLayoutrootlayout;

@Override

public voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_viewpager);

mPager= (ViewPager) findViewById(R.id.main_viewpager);

//返回

ImageView back = (ImageView) findViewById(R.id.back);

back.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

finish();

}

});

Intent intent = getIntent();

String message = intent.getStringExtra("data");

//解析數(shù)據(jù)

//? ? ? ? if (message.length() > 0) {

//? ? ? ? ? ? Gson gson = new Gson();

//? ? ? ? ? ? Main_Data main_data = gson.fromJson(message, new TypeToken() {

//? ? ? ? ? ? }.getType());

//? ? ? ? ? ? tsfbBeans = main_data.getTsfb();

//? ? ? ? }

//構(gòu)造list集合

list=newArrayList();

list.add(R.mipmap.image1);

list.add(R.mipmap.image2);

list.add(R.mipmap.image3);

//? ? ? ? list.add(R.mipmap.image4);

mList=newArrayList();

initView();

}

private voidinitView() {

if(list.size() ==2) {

//如果數(shù)據(jù)是2寒波,就添加兩個(gè)數(shù)組以避免空白頁(yè)

for(intm =0;m <2;m++) {

initValue();

}

}else{

//如果是一個(gè)數(shù)據(jù)那就添加一個(gè)

initValue();

}

adapter=newTTMyPagerAdapters(mList, this);

mPager.setAdapter(adapter);

if(mList.size() >1) {

mPager.setCurrentItem(position);

initAdapter();

}

//? ? ? ? if (mList.size() < 2) {

//

//? ? ? ? } else if (mList.size() == 2) {

//

//? ? ? ? ? ? mPager.setCurrentItem(position + 1);

//? ? ? ? ? ? initAdapter();

//? ? ? ? } else {

//? ? ? ? ? ? mPager.setCurrentItem(position);

//? ? ? ? ? ? initAdapter();

//? ? ? ? }

//mPager.setCurrentItem(count);

mPager.setOnPageChangeListener(listener);

mPager.setOnTouchListener(newView.OnTouchListener() {

@Override

public booleanonTouch(View view,MotionEvent motionEvent) {

return true;

}

});

}

private voidinitValue() {

for(inti =0;i

rootlayout=newRelativeLayout(this);

rootlayout.setLayoutParams(newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT));

rootlayout.setId(0);

ImageView imageView =newImageView(this);

RelativeLayout.LayoutParams image_Params =newRelativeLayout.LayoutParams(

dip2px(250),dip2px(192));

image_Params.setMargins(dip2px(5),0,dip2px(5),dip2px(5));

imageView.setLayoutParams(image_Params);

imageView.setImageResource(list.get(i));

//Picasso.with(ViewPagersActivity.this).load(tsfbBeans.get(i).getBook_pic()).error(R.mipmap.image1).into(imageView);

imageView.setId(1);

//字體顏色

Resources resource = (Resources) getBaseContext().getResources();

ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.book_text);

TextView text_Name =newTextView(this);

RelativeLayout.LayoutParams text_Name_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_Name_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_Name_Params.addRule(RelativeLayout.ALIGN_TOP,imageView.getId());

text_Name_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_Name.setLayoutParams(text_Name_Params);

text_Name.setText("圖書描述:");

//text_Name.setText(tsfbBeans.get(i).getBook_name() + ":");

text_Name.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_Name.setTextColor(csl);

text_Name.setId(2);

TextView text_Email =newTextView(this);

RelativeLayout.LayoutParams text_Email_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_Email_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_Email_Params.addRule(RelativeLayout.BELOW,text_Name.getId());

text_Email_Params.setMargins(dip2px(10),dip2px(5),dip2px(10),0);

text_Email.setLayoutParams(text_Email_Params);

text_Email.setText("《詩(shī)經(jīng)》是中國(guó)古代詩(shī)歌開端乘盼,最早的一部詩(shī)歌總集俄烁,收集了西周初年至春秋中葉(前11世紀(jì)至前6世紀(jì))的詩(shī)歌绸栅,共311篇,其中6篇為笙詩(shī)页屠,即只有標(biāo)題粹胯,沒有內(nèi)容,稱為笙詩(shī)六篇");

//text_Email.setText(tsfbBeans.get(i).getBook_description());

text_Email.setTextSize(TypedValue.COMPLEX_UNIT_SP,13);

text_Email.setId(3);

TextView text_author =newTextView(this);

RelativeLayout.LayoutParams text_author_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_author_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_author_Params.addRule(RelativeLayout.BELOW,text_Email.getId());

text_author_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_author.setLayoutParams(text_author_Params);

text_author.setText("圖書作者:");

//text_author.setText("圖書作者:" + tsfbBeans.get(i).getBook_author());

text_author.setTextColor(csl);

text_author.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_author.setId(4);

TextView text_place =newTextView(this);

RelativeLayout.LayoutParams text_place_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_place_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_place_Params.addRule(RelativeLayout.BELOW,text_author.getId());

text_place_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_place.setLayoutParams(text_place_Params);

text_place.setText("出版社:");

//text_place.setText("出版社:" + tsfbBeans.get(i).getBook_publishing());

text_place.setTextColor(csl);

text_place.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_place.setId(5);

TextView text_data =newTextView(this);

RelativeLayout.LayoutParams text_data_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_data_Params.addRule(RelativeLayout.RIGHT_OF,imageView.getId());

text_data_Params.addRule(RelativeLayout.BELOW,text_place.getId());

text_data_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_data.setLayoutParams(text_data_Params);

text_data.setText("出版日期:");

// text_data.setText("出版日期:" + tsfbBeans.get(i).getBook_publication_date());

text_data.setTextColor(csl);

text_data.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_data.setId(6);

TextView text_description_name =newTextView(this);

RelativeLayout.LayoutParams text_DescriptionName_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_DescriptionName_Params.addRule(RelativeLayout.BELOW,imageView.getId());

//text_Name_Params.addRule(RelativeLayout.ALIGN_TOP, imageView.getId());

text_DescriptionName_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_description_name.setLayoutParams(text_DescriptionName_Params);

text_description_name.setText("圖書簡(jiǎn)介:");

text_description_name.setTextColor(csl);

text_description_name.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);

text_description_name.setId(7);

TextView text_description =newTextView(this);

RelativeLayout.LayoutParams text_Description_Params =newRelativeLayout.LayoutParams(

RelativeLayout.LayoutParams.WRAP_CONTENT,

RelativeLayout.LayoutParams.WRAP_CONTENT);

text_Description_Params.addRule(RelativeLayout.BELOW,text_description_name.getId());

//text_Name_Params.addRule(RelativeLayout.ALIGN_TOP, imageView.getId());

text_Description_Params.setMargins(dip2px(10),dip2px(5),0,0);

text_description.setLayoutParams(text_Description_Params);

text_description.setText("111");

//text_description.setText(tsfbBeans.get(i).getBook_abstract());

text_description.setTextSize(TypedValue.COMPLEX_UNIT_SP,13);

text_description.setId(8);

rootlayout.addView(imageView,image_Params);

rootlayout.addView(text_Name,text_Name_Params);

rootlayout.addView(text_Email,text_Email_Params);

rootlayout.addView(text_description,text_Description_Params);

rootlayout.addView(text_author,text_author_Params);

rootlayout.addView(text_place,text_place_Params);

rootlayout.addView(text_data,text_data_Params);

rootlayout.addView(text_description_name,text_DescriptionName_Params);

//setContentView(rootlayout);

mList.add(rootlayout);

}

}

ViewPager.OnPageChangeListenerlistener=newViewPager.OnPageChangeListener() {

@Override

public voidonPageSelected(intarg0) {

//TODO Auto-generated method stub

//LogUtil.e("當(dāng)前頁(yè)面索引:" + arg0);

}

@Override

public voidonPageScrolled(intarg0, floatarg1, intarg2) {

//TODO Auto-generated method stub

}

@Override

public voidonPageScrollStateChanged(intarg0) {

//TODO Auto-generated method stub

}

};

private voidinitAdapter() {

Share.d("mlist"+mList.size());

//

//TODO Auto-generated method stub

//TODO Auto-generated catch block

change=newThread(newRunnable() {

@Override

public voidrun() {

//TODO Auto-generated method stub

while(true) {

handler.sendEmptyMessage(0);

try{

Thread.sleep(5000);

}catch(InterruptedException e) {

//TODO Auto-generated catch block

e.printStackTrace();

}

}

}

});

change.start();

}

@SuppressLint("HandlerLeak")

privateHandlerhandler=newHandler() {

@Override

public voidhandleMessage(Message msg) {

super.handleMessage(msg);

switch(msg.what) {

case0:

position++;

mPager.setCurrentItem(position);

break;

default:

break;

}

}

};

public intdip2px(floatdpValue) {

final floatscale =this.getResources().getDisplayMetrics().density;

return(int) (dpValue * scale +0.5f);

}

@Override

protected voidonDestroy() {

super.onDestroy();

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末辰企,一起剝皮案震驚了整個(gè)濱河市风纠,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌牢贸,老刑警劉巖竹观,帶你破解...
    沈念sama閱讀 216,402評(píng)論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡臭增,警方通過(guò)查閱死者的電腦和手機(jī)懂酱,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)誊抛,“玉大人列牺,你說(shuō)我怎么就攤上這事∞智裕” “怎么了瞎领?”我有些...
    開封第一講書人閱讀 162,483評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)并炮。 經(jīng)常有香客問(wèn)我默刚,道長(zhǎng),這世上最難降的妖魔是什么逃魄? 我笑而不...
    開封第一講書人閱讀 58,165評(píng)論 1 292
  • 正文 為了忘掉前任荤西,我火速辦了婚禮,結(jié)果婚禮上伍俘,老公的妹妹穿的比我還像新娘邪锌。我一直安慰自己,他們只是感情好癌瘾,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,176評(píng)論 6 388
  • 文/花漫 我一把揭開白布觅丰。 她就那樣靜靜地躺著,像睡著了一般妨退。 火紅的嫁衣襯著肌膚如雪妇萄。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,146評(píng)論 1 297
  • 那天咬荷,我揣著相機(jī)與錄音冠句,去河邊找鬼。 笑死幸乒,一個(gè)胖子當(dāng)著我的面吹牛懦底,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播罕扎,決...
    沈念sama閱讀 40,032評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼聚唐,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了腔召?” 一聲冷哼從身側(cè)響起杆查,我...
    開封第一講書人閱讀 38,896評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎宴咧,沒想到半個(gè)月后根灯,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,311評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡掺栅,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,536評(píng)論 2 332
  • 正文 我和宋清朗相戀三年烙肺,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片氧卧。...
    茶點(diǎn)故事閱讀 39,696評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡桃笙,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出沙绝,到底是詐尸還是另有隱情搏明,我是刑警寧澤,帶...
    沈念sama閱讀 35,413評(píng)論 5 343
  • 正文 年R本政府宣布闪檬,位于F島的核電站星著,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏粗悯。R本人自食惡果不足惜虚循,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,008評(píng)論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望样傍。 院中可真熱鬧横缔,春花似錦、人聲如沸衫哥。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)撤逢。三九已至膛锭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間蚊荣,已是汗流浹背初狰。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留妇押,地道東北人跷究。 一個(gè)月前我還...
    沈念sama閱讀 47,698評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像敲霍,于是被迫代替她去往敵國(guó)和親俊马。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,592評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容