Android implements continuous sliding of images of gongge

Source: Internet
Author: User

  This article describes how to achieve continuous sliding of images in Android.

 

  Before that, I wrote a few articles about the sliding effect in Android. After all, the sliding effect is also frequently used in Andriod development. If you are interested, please refer to my previous articles, I will not detail it here.

 

The reason why I wrote this article today is that a netizen posted a message on my blog some time ago, and wanted to implement it in GridLayout (equivalent to jiugongge) click each item to slide left and right to display the image of the cell. When the image of the cell is displayed, the image of the next cell is displayed. So I have read my previous articles on slide. I believe it is not difficult to achieve the effect of the former. The key lies in how to implement the latter, that is, how can I see the image of a palace lattice, then, the image of the next cell is displayed. This is what we will discuss in this article.

  

Speaking of this, I would like to say sorry to this netizen because I was too busy some days ago and now I have some time to write this article. After all, my work is busy, you cannot answer your questions in real time. Please forgive me.

 

Let's get down to the truth and continue to introduce our content. In this article, what kind of functions are provided in our implementation example? In order for you to learn more about Android, in addition to implementing the functions discussed above, this example also implements the following functions:

  1. Multi-threaded image loading;
  2. Images can be viewed automatically;
  3. The header and bottom can be hidden;
  4. When an image is loaded, the flop effect can be displayed;
  5. 3D switching is achieved during COAG switching;
  6. You can switch the gongge image to the ListView style;
  7. You can configure various options, such as cache size, thread pool size, and image display.

 

For better understanding, Let's first look at the implementation:

 

After reading this, you will feel familiar. That's right, because this effect is common in the News client and can also be used in other applications.

 

Let's start the implementation process.

Familiarize yourself with the MainActivity. java code as follows:

Package com. palace. image. activity; import com. image. loader. core. displayImageOptions; import com. palace. image. r; import com. palace. image. adapter. gridViewAdapter; import android. content. intent; import android. graphics. color; import android. graphics. drawable. colorDrawable; import android. OS. bundle; import android. view. view; import android. widget. adapterView; import android. widget. gridView; import android. widget. AdapterView. onItemClickListener;/*** Android achieves the continuous sliding effect of a grid image * @ Description: Android achieves the continuous sliding effect of a grid image * @ File: MainActivity. java * @ Package com. palace. image. activity * @ Author Hanyonglu * @ Date 05:57:34 * @ Version V1.0 */public class MainActivity extends BaseActivity {private GridView gridView = null; private String [] imageValues = null; private String [] titleValues = null; private DisplayIm AgeOptions options;/** Called when the activity is first created. * // @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main_activity); // initialize initViews ();}/*** initialize */private void initViews () {titleValues = getResources (). getStringArray (R. array. news_title); imageValues = getResources (). getStringArray (R. array. small_images); o Ptions = new DisplayImageOptions. builder (). showStubImage (R. drawable. ic_image_load ). showImageForEmptyUri (R. drawable. ic_image_load ). cacheInMemory (). cacheOnDisc (). build (); gridView = (GridView) findViewById (R. id. gridview); gridView. setSelector (new ColorDrawable (Color. TRANSPARENT); gridView. setAdapter (new GridViewAdapter (this, imageValues, titleValues, imageLoader, options); gridView. setOnItemCli CkListener (itemOnClickListener);} // GridView click the item event listener private OnItemClickListener itemOnClickListener = new OnItemClickListener () {public void onItemClick (AdapterView <?> Parent, View v, int position, long id) {Intent intent = new Intent (); intent. setClass (MainActivity. this, ImageActivity. class); intent. putExtra ("item_index", position); startActivity (intent) ;};@ Override protected void onStop () {super. onStop (); imageLoader. stop () ;}@ Override protected void onDestroy () {// TODO Auto-generated method stub super. onDestroy (); imageLoader. stop ();}}

 

Finally, I hope to reprint friends can respect the author's labor results, plus reprint address: http://www.cnblogs.com/hanyonglu/archive/2012/09/19/2693465.html thank you.

 

To be continued. Pai_^

 

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.