Android Project Combat--listview Head Viewpager AD Poll chart effect

Source: Internet
Author: User

Look at the Open source framework: Https://github.com/tianshaojie/AndroidFine, which has the following effects, special record learning, later in the project can be remembered immediately.As shown above, is a common project in the picture rotation and display effect, the technology is mainly related to Viewpager+photoview, the following is mainly about how to achieve this effect in the Android app:
    1. Import Photoview Related code:
    2.head Rotation and display code:    
implementation of the 1th page:First look at the layout:activity_photoview.xml File
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "160DP"Android:background= "@color/white" >    <Com.soyoungboy.widget.loopviewpager.AutoLoopViewPagerAndroid:id= "@+id/pager"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" />    <Com.soyoungboy.widget.viewpagerindicator.CirclePageIndicatorAndroid:id= "@+id/indicator"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_centerhorizontal= "true"Android:layout_marginbottom= "5DP"android:padding= "5DP" /></Relativelayout>

Photoviewactivity.java File
  1.  Public classPhotoviewactivityextendsbasefragmentactivity {PrivateCom.soyoungboy.widget.loopviewpager.AutoLoopViewPager Pager; Private int[] imageviewids; PrivateCom.soyoungboy.widget.viewpagerindicator.CirclePageIndicator indicator; PrivateList<string> imageList =NewArraylist<string>(Arrays.aslist ("Http://pic.nipic.com/2008-07-11/20087119630716_2.jpg",            "Http://pic.nipic.com/2008-07-11/20087119630716_2.jpg",            "Http://pic.nipic.com/2008-07-11/20087119630716_2.jpg")); @Overrideprotected voidonCreate (Bundle arg0) {Super. OnCreate (arg0);        Setcontentview (R.layout.activity_photoview);    Initview (); } @Overrideprotected voidInitview () {pager=(Com.soyoungboy.widget.loopviewpager.AutoLoopViewPager) Findviewbyid (R.id.pager); Indicator=(Com.soyoungboy.widget.viewpagerindicator.CirclePageIndicator) Findviewbyid (r.id.indicator); //set the picture content to be displayedImageviewids =New int[] {r.drawable.house_background, r.drawable.house_background_1, r.drawable.house_background_2}; //AdapterGallerypageradapter Galleryadapter =NewGallerypageradapter ();        Pager.setadapter (Galleryadapter);        Indicator.setviewpager (pager); //control distance to the left, top, right, bottom px distanceIndicator.setpadding (5, 5, 10, 5); } @Overrideprotected voidInittitleview () {} @Overrideprotected voidClick (view view) {}//Carousel Diagram Adapter     Public classGallerypageradapterextendsPageradapter {@Override Public intGetCount () {returnimageviewids.length; } @Override Public Booleanisviewfromobject (View view, Object object) {returnView = =object; } @Override PublicObject Instantiateitem (ViewGroup container,intposition) {ImageView Item=NewImageView (photoviewactivity. This); //ImageView above display pictureItem.setimageresource (imageviewids[position]); Viewgroup.layoutparams params=NewViewgroup.layoutparams (-1,-1);            Item.setlayoutparams (params);            Item.setscaletype (ImageView.ScaleType.FIT_XY);            Container.addview (item); Final intpos =position; //ImageView Click event HandlingItem.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//go inside the imagegalleryactivity code.Intent Intent =NewIntent (photoviewactivity. This, Imagegalleryactivity.class); Intent.putstringarraylistextra ("Images", (arraylist<string>) imageList); Intent.putextra ("Position", POS);                StartActivity (Intent);            }            }); returnitem; } @Override Public voidDestroyitem (ViewGroup collection,intposition, Object view)        {Collection.removeview (view) view); }} @Overrideprotected voidOnresume () {Super. Onresume (); //start automatic left and right toggle picturePager.startautoscroll (); } @Overrideprotected voidOnPause () {Super. OnPause (); //end automatic left and right toggle picturePager.stopautoscroll (); }}


The 2nd graph function realizes:First layout fileActivity_touch_gallery.xml

  1. <?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:fitssystemwindows= "true"Android:background= "@color/black">        <Android.support.v4.view.ViewPagerAndroid:id= "@+id/viewer"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:layout_below= "@+id/layoutheader" /></Relativelayout>


imagegalleryactivity . Java
 Public classImagegalleryactivityextendsbasefragmentactivity {Private intposition; PrivateList<string> Imgurls;//Picture List    PrivateTextView Headtitle; PrivateButton headbackbtn; PrivateViewpager Mviewpager; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_touch_gallery); Intent Intent=getintent (); Position= Intent.getintextra ("position", 0); //gets the URL of the Picture list collectionImgurls = Intent.getstringarraylistextra ("Images"); if(Imgurls = =NULL) {Imgurls=NewArraylist<>();    } initgalleryviewpager (); } @Overrideprotected voidOnDestroy () {Super. OnDestroy (); }    Private voidInitgalleryviewpager () {photoviewadapter pageradapter=NewPhotoviewadapter ( This, Imgurls); Pageradapter.setonitemchangelistener (NewPhotoviewadapter.onitemchangelistener () {intLen =imgurls.size (); @Override Public voidOnItemChange (intcurrentposition) {                //slide to a fraction of the total number of pictures//Headtitle.settext ((currentposition+1) + "/" + len);                            }        }); Mviewpager=(Viewpager) Findviewbyid (r.id.viewer); Mviewpager.setoffscreenpagelimit (3);        Mviewpager.setadapter (Pageradapter);    Mviewpager.setcurrentitem (position); } @Overrideprotected voidInitview () {} @Overrideprotected voidInittitleview () {} @Overrideprotected voidClick (view view) {}}

Photoviewadapter Code can refer to:https://github.com/tianshaojie/AndroidFine/blob/master/app/src/main/java/com/yuzhi/fine/ui/photoview/ Photoviewadapter.java Loopviewpager Package code can refer to:Https://github.com/tianshaojie/AndroidFine/tree/master/app/src/main/java/com/yuzhi/fine/ui/loopviewpager

Android Project Combat--listview Head Viewpager AD Poll chart effect

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.