Android ImageSwitcher and imageswitcher

Source: Internet
Author: User

Android ImageSwitcher and imageswitcher

<?xml version="1.0" encoding="UTF-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <ImageSwitcher        android:id="@+id/switcher"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true" />    <Gallery        android:id="@+id/gallery"        android:layout_width="fill_parent"        android:layout_height="60dp"        android:layout_alignParentBottom="true"        android:layout_alignParentLeft="true"        android:background="#ff00ff"        android:gravity="center_vertical"        android:spacing="16dp" /></RelativeLayout>
Package com. example. yanlei. mytk; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. view. view; import android. widget. adapterView; import android. widget. arrayAdapter; import android. widget. button; import android. widget. spinner; import java. util. arrayList; import java. util. list; import android. app. activity; import android. content. context; import android. OS. bundle; import and Roid. view. view; import android. view. viewGroup; import android. view. animation. animationUtils; import android. widget. adapterView; import android. widget. baseAdapter; import android. widget. gallery; import android. widget. gallery. layoutParams; import android. widget. imageSwitcher; import android. widget. imageView; import android. widget. viewSwitcher; public class MainActivity extends AppCompatActivity implements Vie WSwitcher. viewFactory {private ImageSwitcher mSwitcher; private Gallery gallery; private Context mContext; private Integer [] mImageIds = {R. drawable. sample_0, R. drawable. sample_1, R. drawable. sample_2, R. drawable. sample_3, R. drawable. sample_4, R. drawable. sample_5, R. drawable. sample_6, R. drawable. sample_7, R. drawable. sample_8, R. drawable. sample_9, R. drawable. sample_10, R. drawable. sample_11}; @ Over Ride protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); setTitle ("browse image"); mSwitcher = (ImageSwitcher) findViewById (R. id. switcher); gallery = (Gallery) findViewById (R. id. gallery); mSwitcher. setFactory (this); mSwitcher. setInAnimation (AnimationUtils. loadAnimation (this, android. r. anim. fade _ In); mSwitcher. setInAnimation (AnimationUtils. loadAnimation (this, android. r. anim. fade_out); gallery. setAdapter (new ImageAdapter (this); gallery. setOnItemSelectedListener (new AdapterView. onItemSelectedListener () {@ Override public void onItemSelected (AdapterView <?> Adapter, View view, int position, long id) {mSwitcher. setImageResource (mImageIds [position]) ;}@ Override public void onNothingSelected (AdapterView <?> Arg0) {}});} public class ImageAdapter extends BaseAdapter {public ImageAdapter (Context context) {mContext = context ;}@ Override public int getCount () {return mImageIds. length ;}@ Override public Object getItem (int position) {return position ;}@ Override public long getItemId (int position) {return position ;}@ Override public View getView (int position, view convertView, ViewGroup parent) {ImageView I = new ImageView (mContext); I. setImageResource (mImageIds [position]); I. setAdjustViewBounds (true); I. setLayoutParams (new Gallery. layoutParams (LayoutParams. WRAP_CONTENT, LayoutParams. WRAP_CONTENT); I. setBackgroundResource (R. drawable. picture_frame); return I ;}@ Override public View makeView () {ImageView I = new ImageView (this); I. setBackgroundColor (0xFF000000); I. setScaleType (ImageView. scaleType. FIT_CENTER); I. setLayoutParams (new ImageSwitcher. layoutParams (LayoutParams. FILL_PARENT, LayoutParams. FILL_PARENT); return I ;}}

 

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.