Is a man on the next layer 100 [second layer] -- help beautiful women change clothes (1)

Source: Internet
Author: User

Some time last year, there was an application with a high volume of downloads, which was all contributed by male. Now the second version is available. On the second layer, we will implement the application "Helping beautiful women change clothes, many boys should be familiar with this application. Here I will not explain the content.

First, let's look at the effect we want to achieve:

(Terrible! After completing the work, let's dig for the rest)

First look at the layout file activity_main.xml

<?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/image_switcher"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true" />    <Gallery        android:id="@+id/gallery"        android:layout_width="fill_parent"        android:layout_height="80.0dip"        android:layout_alignParentBottom="true"        android:layout_alignParentLeft="true"        android:background="#55000000"        android:gravity="center_vertical"        android:spacing="15.0dip" /></RelativeLayout>

ImageSwitcher inherits from ViewSwitcher and overwrites the showNext () and showPrevious () methods.

To use ImageSwithcer, follow these steps:

1. Provide a ViewFactory for ImageSwitcher. This ViewFactory has a makeView () method to generate the View component, which must be ImageView.

2. When switching an image, you only need to call the setImageDrawable (Drawable drawable) method, setImageResource (int resid) method, or setImageURI (Uri uri Uri ).

Package com. example. mygrilproject; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. view. viewGroup; import android. widget. adapterView; import android. widget. adapterView. onItemSelectedListener; import android. widget. baseAdapter; import android. widget. gallery; import android. widget. gallery. la YoutParams; import android. widget. imageSwitcher; import android. widget. imageView; import android. widget. imageView. scaleType; import android. widget. viewSwitcher. viewFactory; public class MainActivity extends Activity implements ViewFactory {private ImageSwitcher is; private Gallery gallery; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layo Ut. activity_main); // obtain the ImageSwitcher object is = (ImageSwitcher) findViewById (R. id. image_switcher); is. setFactory (this); // obtain the gallery object gallery = (Gallery) findViewById (R. id. gallery); // set the adapter gallery. setAdapter (new ImageAdapter (MainActivity. this); // set to listen to gallery. setOnItemSelectedListener (new OnItemSelectedListener () {@ Overridepublic void onItemSelected (AdapterView <?> Parent, View view, int position, long id) {int drawableId = 0; try {drawableId = R. drawable. class. getDeclaredField ("pre" + position ). getInt (this);} catch (IllegalArgumentException e) {e. printStackTrace ();} catch (SecurityException e) {e. printStackTrace ();} catch (IllegalAccessException e) {e. printStackTrace ();} catch (NoSuchFieldException e) {e. printStackTrace ();} // replace image I in ImageSwitcher S. setImageResource (drawableId) ;}@ Overridepublic void onNothingSelected (AdapterView <?> Parent) {}}); is. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {}}) ;}// set the animation effect of image switching @ Overridepublic View makeView () {ImageView I = new ImageView (this); I. setBackgroundColor (0xFF000000); I. setScaleType (ImageView. scaleType. FIT_CENTER); I. setLayoutParams (new ImageSwitcher. layoutParams (LayoutParams. MATCH_PARENT, LayoutParams. MATCH_PARENT); return I;} private class ImageAdapter extends BaseAdapter {private Context mContext; public ImageAdapter (Context c) {mContext = c ;}@ Overridepublic int getCount () {return 11; // 11 images} @ Overridepublic Object getItem (int position) {return position ;}@ Overridepublic long getItemId (int position) {return position ;}@ Overridepublic View getView (int position, view convertView, ViewGroup parent) {ImageView imageView = new ImageView (mContext); int drawableId = 0; try {// obtain resource object drawableId = R using reflection. drawable. class. getDeclaredField ("pre" + position ). getInt (this);} catch (IllegalArgumentException e) {e. printStackTrace ();} catch (SecurityException e) {e. printStackTrace ();} catch (IllegalAccessException e) {e. printStackTrace ();} catch (NoSuchFieldException e) {e. printStackTrace ();} imageView. setLayoutParams (new Gallery. layoutParams (120,120); imageView. setScaleType (ScaleType. FIT_XY); imageView. setImageResource (drawableId); return imageView ;}}}
Running effect:



Next, let's take a look at how to tear your clothes.

Source code download: http://download.csdn.net/detail/lxq_xsyu/7014543


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.