[Android: What do you want to talk about?] superb left-side sliding effect-viewpager usage

Source: Internet
Author: User

1. Example description 

• Android-support-v4.jar, a software package officially provided to us by Google that is compatible with low-version Android devices and contains APIs that can only be used in Android 3.0 and later versions. Viewpager is one of them. With viewpager, we can do many things, from the simplest navigation to page switching menus. • Viewpager allows the view to slide, just as the lanucher slides left and right. • This demo shows you how to use viewpager. When you do not slide the view, the system automatically switches to the next view every 5s (Cyclic switching ), when a user has a touch to view, the 5S automatic switch function is canceled. There is an indicator to indicate which view is currently in.

2. Running result

3. Core code

Private void initviewpager (){

advPager = (ViewPager) findViewById(R.id.adv_pager);ViewGroup group = (ViewGroup) findViewById(R.id.viewGroup);List<View> advPics = new ArrayList<View>();ImageView img1 = new ImageView(this);img1.setBackgroundResource(R.drawable.advertising_default_1);advPics.add(img1);ImageView img2 = new ImageView(this);img2.setBackgroundResource(R.drawable.advertising_default_2);advPics.add(img2);ImageView img3 = new ImageView(this);img3.setBackgroundResource(R.drawable.advertising_default_3);advPics.add(img3);ImageView img4 = new ImageView(this);img4.setBackgroundResource(R.drawable.advertising_default);advPics.add(img4);imageViews = new ImageView[advPics.size()];for (int i = 0; i < advPics.size(); i++) {imageView = new ImageView(this);imageView.setLayoutParams(new LayoutParams(20, 20));imageView.setPadding(5, 5, 5, 5);imageViews[i] = imageView;if (i == 0) {imageViews[i].setBackgroundResource(R.drawable.banner_dian_focus);} else {imageViews[i].setBackgroundResource(R.drawable.banner_dian_blur);}group.addView(imageViews[i]);}advPager.setAdapter(new AdvAdapter(advPics));advPager.setOnPageChangeListener(new GuidePageChangeListener());advPager.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:case MotionEvent.ACTION_MOVE:isContinue = false;break;case MotionEvent.ACTION_UP:isContinue = true;break;default:isContinue = true;break;}return false;}});new Thread(new Runnable() {@Overridepublic void run() {while (true) {if (isContinue) {viewHandler.sendEmptyMessage(what.get());whatOption();}}}}).start();}

4. extended learning and Video Explanation

Http://www.eyeandroid.com/thread-11355-1-1.html

 
Related Article

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.