最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android ViewPager实现左右滑动翻页效果
时间:2022-06-25 23:07:18 编辑:袖梨 来源:一聚教程网
本文实例为大家分享了ViewPager实现左右滑动翻页效果展示的具体代码,供大家参考,具体内容如下
代码如下:
package com.example.demo; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewPager mViewPager=(ViewPager) findViewById(R.id.viewPager); PagerAdapter mPagerAdapter=new MyPagerAdapter(this); mViewPager.setAdapter(mPagerAdapter); } private class MyPagerAdapter extends PagerAdapter{ private Context context; private ArrayListviews; public MyPagerAdapter(Context context){ this.context=context; views=new ArrayList (); for(int i=0;i<30;i++){ TextView tv=new TextView(context); tv.setText(""+i); views.add(tv); } } @Override public int getCount() { return views.size(); } @Override public void destroyItem(ViewGroup container, int position,Object object) { container.removeView(views.get(position)); } @Override public View instantiateItem(ViewGroup container, int position){ ((ViewGroup) container).addView(views.get(position)); return views.get(position); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0==arg1; } } }
布局文件:
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22