Android App boot interface-viewpages use

Source: Internet
Author: User

The Viewpager function is to make the view slide. Can be used to do navigation, page menu. Adapter Pageradapter is required for use. Therefore, the need to inherit the pageradapter, the implementation of the boot interface requires at least 4 methods: Instantiateitem (ViewGroup, int): Used to create a page at a specified location; Destroyitem (ViewGroup, int, Object): Destroys a page at the specified location; GetCount (): number of pages; Isviewfromobject (View, Object) : Used to determine whether a view of pager is associated with the object returned by the Instantiateitem method.
  
 
  1. // 初始化引导图片列表
  2. VI Ew1 = Inflater inflate ( r layout page_one null );
  3. VI Ew2 = Inflater inflate ( r layout page_two null );
  4. view3 = inflater.inflate(R.layout.page_three, null);
  5. viewList = new ArrayList<View>();// 将要分页显示的View装入数组中
  6. viewList.add(view1);
  7. viewList.add(view2);
  8. viewList.add(view3);
  9. viewPager = (ViewPager) findViewById(R.id.viewpager);
  10. // 初始化Adapter,重写PagerAdapter
  11. PagerAdapter pagerAdapter = new PagerAdapter() {
  12. @Override
  13. public boolean isViewFromObject(View view, Object object) {
  14. return view == object;//该object其实就是viewPager添加的view
  15. }
  16. @Override
  17. public int getCount() {
  18. return viewList.size();
  19. }
  20. @Override
  21. public void ( viewgroup container int object object {
  22. container.removeView(viewList.get(position));
  23. }
  24. @Override
  25. public int getItemPosition(Object object) {
  26. return super.getItemPosition(object);
  27. }
  28. @Override
  29. public CharSequence getPageTitle(int position) {
  30. return super.getPageTitle(position);
  31. }
  32. @Override
  33. public object Instantiateitem ( view container int position {
  34. ((ViewPager)container).addView(viewList.get(position));
  35. return viewList.get(position);
  36. }
  37. };
  38. viewPager.setAdapter(pagerAdapter);
  39. // 绑定回调


Reference: http://blog.csdn.net/wangjinyu501/article/details/8169924


From for notes (Wiz)

Android App boot interface-viewpages use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.