Android's Imageswitcher

Source: Internet
Author: User

Points:

(View API Summary)

1:imageswitcher inherit Viewswitcher, (Viewswitcher has inheritance framelayout)

2: To implement the cut graph must implement the Makeview () in the Viewswitcher.viewfactory interface

Easy Error Point:

1:

Mimageswitcher.setfactory (this);
Mimageswitcher.setimageresource (Mimages[0]);

Setimageresource must be called after setfactory. Reason: According to the source code analysis call Setfactory get interface, can

Gets the view returned by Makeview () otherwise throws a null pointer exception

2: Set layout parameters in Makeview with framelayout layout parameters

Package Com.imageswitcher;import Android.app.activity;import Android.os.bundle;import android.util.Log;import Android.view.view;import Android.view.viewgroup;import Android.view.animation.animationutils;import Android.widget.framelayout;import Android.widget.imageswitcher;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.toast;import Android.widget.viewswitcher;public Class    Mainactivity extends Activity implements Viewswitcher.viewfactory {private LinearLayout mlinearlayout;    Private Imageswitcher Mimageswitcher;            Private integer[] Mimages = {r.drawable.android01, r.drawable.android02, R.DRAWABLE.ANDROID03, R.DRAWABLE.ANDROID04,    R.DRAWABLE.ANDROID05, R.drawable.android06, r.drawable.android07, r.drawable.android08, R.drawable.android09};        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Initview (); MimageswiTcher.setfactory (this);        Mimageswitcher.setimageresource (Mimages[0]); Mimageswitcher.setinanimation (Animationutils.loadanimation (this, Android.        r.anim.fade_in)); Mimageswitcher.setoutanimation (Animationutils.loadanimation (this, Android.        R.anim.fade_out));        for (int i = 0; i < mimages.length; i++) {Mlinearlayout.addview (Getimageview (i));        }} private ImageView Getimageview (final int i) {ImageView ImageView = new ImageView (this);        Imageview.setimageresource (Mimages[i]);        Imageview.setid (i);                Imageview.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {                Mimageswitcher.setimageresource (Mimages[i]);            Toast.maketext (V.getcontext (), "selected" + (V.getid () + 1) + "map", Toast.length_short). Show ();        }        });    return imageView; } private void Initview () {mlinearlayout = (linearlayout) Findviewbyid (R.id.linEarlayout);    Mimageswitcher = (imageswitcher) Findviewbyid (R.id.imageswitcher);        } @Override Public View Makeview () {ImageView ImageView = new ImageView (this);        LOG.I (MainActivity.class.getSimpleName (), "First Call"); Imageview.setlayoutparams (New Framelayout.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, viewgroup.layou        Tparams.match_parent));    return imageView; }}

  

Xml

<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Mainactivity ">    <ImageswitcherAndroid:id= "@+id/imageswitcher"Android:layout_width= "Match_parent"Android:layout_height= "200DP">            </Imageswitcher>    <HorizontalscrollviewAndroid:layout_below= "@id/imageswitcher"Android:layout_width= "Match_parent"Android:layout_height= "100DP"        >                <LinearLayoutAndroid:id= "@+id/linearlayout"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:orientation= "Horizontal">        </LinearLayout>            </Horizontalscrollview></Relativelayout>

Android's Imageswitcher

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.