Android drag photo effects

Source: Internet
Author: User

Have you ever been attracted by the iPhone dragging photos with your fingers on the screen? It can also be implemented in Android, and it is not difficult.

Android. content. Context; Android. widget. baseadapter; Android. wiiot. imageview; and so on are required.

Android. content. context is similar to a canvas in the activity and can be processed or overwritten at any time. Context is a subclass of Android. content like intent.

In this example, you can place the gallery object in layout and then use the Android. widget. baseadapter container to place the image required by gallery. In this case, the system uses the default icon image.

1. Drag the gallery control to layout and set the ID to mygallery1.


View Res/layout/Main. xml

<? XML version ="1.0"Encoding ="UTF-8"?> <Linearlayout xmlns: Android ="Http://schemas.android.com/apk/res/android"Android: Orientation ="Vertical"Android: layout_width ="Fill_parent"Android: layout_height ="Fill_parent"> <Gallery Android: layout_width ="Fill_parent"Android: layout_height ="Wrap_content"Android: Id ="@ + ID/mygallery1"> </Gallery> </linearlayout>

Src/ex03_15.java

Package gphone. ex03_15; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. view; import android. view. viewgroup; import android. widget. baseadapter; import android. widget. gallery; import android. widget. imageview; public class ex03_15 extends activity {private gallery mygallery1 = NULL;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mygallery1 = (Gallery) findviewbyid (R. id. mygallery1); mygallery1.setadapter (New imageadapter (this);} public class imageadapter extends baseadapter {private context mycontext; // use android. r. in drawable, the system uses the default image as the image source private int [] myimageids = {android. r. drawable. btn_minus, android. r. drawable. btn_radio, android. r. drawable. ic_lock_idle_low_battery, android. r. drawable. ic_menu_camera, android. r. drawable. btn_minus, android. r. drawable. btn_radio, android. r. drawable. ic_lock_idle_low_battery, android. r. drawable. ic_menu_camera, android. r. drawable. btn_minus, android. r. drawable. btn_radio, android. r. drawable. ic_lock_idle_low_battery, android. r. drawable. ic_menu_camera}; Public imageadapter (context c) {This. mycontext = C ;}@ override public int getcount () {// todo auto-generated method stub return this. myimageids. length ;}@ override public object getitem (INT position) {// todo auto-generated method stub return position ;}@ override public long getitemid (INT position) {// todo auto-generated method stub return position;} @ override public view getview (INT position, view convertview, viewgroup parent) {// create imageview I = new imageview (this. mycontext); I. setimageresource (this. myimageids [position]); I. setscaletype (imageview. scaletype. fit_xy); // set the width and height of the imageview object, in the unit of dip I. setlayoutparams (new gallery. layoutparams (120,120); return I;} // getscale is used based on the center displacement to return the size of views (0.0f-1.0f) public float getscale (Boolean focused, int offset) {return math. max (0, 1.0f/(float) math. pow (2, math. ABS (offset )));}}}

Running 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.