博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
viewpager
阅读量:6281 次
发布时间:2019-06-22

本文共 4977 字,大约阅读时间需要 16 分钟。

  hot3.png

public class HelpAdapter extends PagerAdapter{        private Context context;        public HelpAdapter(Context context) {            this.context = context;        }        @Override        public int getCount() {            return list.size();        }        @Override        public boolean isViewFromObject(View view, Object object) {            return view==object;        }        @Override        public Object instantiateItem(ViewGroup container, int position) {        	 View view= LayoutInflater.from(context).inflate(R.layout.item_ad,null);             ImageView imv= (ImageView) view.findViewById(R.id.imv_ad_item);             ImageLoaderService.displayImage(options, imv,list.get(position));             container.addView(view);             return view;        }        @Override        public void destroyItem(ViewGroup container, int position, Object object) {            container.removeView((View) object);        }    }
private ImageView[] dotViews;    private LinearLayout ll_help_dot;    private void initDots() {        // TODO Auto-generated method stub        LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);        mParams.setMargins(smg.dip2px(4), 0, smg.dip2px(4), 0);        dotViews = new ImageView[list.size()];        for(int i = 0; i < list.size(); i++)        {            ImageView imv_dot = new ImageView(this);            imv_dot.setBackgroundResource(R.drawable.icon_weixuanzhong_2x_selector);            imv_dot.setLayoutParams(mParams);            if(i== 0)            {                imv_dot.setSelected(true);            }            else {                imv_dot.setSelected(false);            }            dotViews[i] = imv_dot;            ll_help_dot.addView(dotViews[i]);        }    }

更新

public class FlashActivity extends BaseActivity {    private ViewPager viewPageFlash;    private PagerAdapter pagerAdapter;    private List
viewList; private ImageView[] dotViews; private LinearLayout ll_dot; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flash); viewPageFlash=findViewById(R.id.viewPageFlash); viewList=new ArrayList<>(); initDots(); pagerAdapter=new PagerAdapter() { @Override public int getCount() { return viewList.size(); } @Override public Object instantiateItem(ViewGroup container, int position) { // TODO Auto-generated method stub container.addView(viewList.get(position)); return viewList.get(position); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } }; viewPageFlash.setAdapter(pagerAdapter); viewPageFlash.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { for(int i = 0; i < dotViews.length; i++) { if(position == i) { dotViews[i].setSelected(true); } else { dotViews[i].setSelected(false); } } } @Override public void onPageScrollStateChanged(int state) { } }); } private void initDots() { // TODO Auto-generated method stub ll_dot=findViewById(R.id.ll_dot); LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); DisplayMetrics displayMetrics=getResources().getDisplayMetrics(); mParams.setMargins(displayMetrics.densityDpi*4, 0, displayMetrics.densityDpi*4, 0); dotViews = new ImageView[viewList.size()]; for(int i = 0; i < viewList.size(); i++) { ImageView imv_dot = new ImageView(this); imv_dot.setBackgroundResource(R.drawable.ic_launcher_background); imv_dot.setLayoutParams(mParams); if(i== 0) { imv_dot.setSelected(true); } else { imv_dot.setSelected(false); } dotViews[i] = imv_dot; ll_dot.addView(dotViews[i]); } } public void skip(View view) { startActivity(new Intent(getContext(),MainActivity.class)); }}

 

转载于:https://my.oschina.net/wfy94/blog/2209455

你可能感兴趣的文章
Apache kafka 简介
查看>>
socket通信Demo
查看>>
技术人员的焦虑
查看>>
js 判断整数
查看>>
建设网站应该考虑哪些因素
查看>>
mongodb $exists
查看>>
js实现页面跳转的几种方式
查看>>
sbt笔记一 hello-sbt
查看>>
常用链接
查看>>
pitfall override private method
查看>>
!important 和 * ----hack
查看>>
聊天界面图文混排
查看>>
控件的拖动
查看>>
svn eclipse unable to load default svn client的解决办法
查看>>
Android.mk 文件语法详解
查看>>
QT liunx 工具下载
查看>>
内核源码树
查看>>
Java 5 特性 Instrumentation 实践
查看>>
AppScan使用
查看>>
Java NIO框架Netty教程(三) 字符串消息收发(转)
查看>>