Android implements continuous sliding of images of gongge
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:
Multi-threaded image loading;
Images can be viewed automatically;
The header and bottom can be hidden;
When an image is loaded, the flop effect can be displayed;
3D switching is achieved during COAG switching;
You can switch the gongge image to the ListView style;
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 implements continuous sliding of images in the palace Lattice
* @ Description: Android: implements continuous sliding of images with cells.
* @ 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 DisplayImageOptions;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Initialization
InitViews ();
}
/**
* Initialization
*/
Private void initViews (){
TitleValues = getResources (). getStringArray (R. array. news_title );
ImageValues = getResources (). getStringArray (R. array. small_images );
Options = 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. setOnItemClickListener (new OnItemClickListener (){
Public void onItemClick (AdapterView parent, View v,
Int position, long id ){
Intent intent = new Intent ();
Intent. setClass (MainActivity. this, ImageActivity. class );
StartActivity (intent );
}
});
}
@ Override
Protected void onStop (){
Super. onStop ();
ImageLoader. stop ();
}
@ Override
Protected void onDestroy (){
// TODO Auto-generated method stub
Super. onDestroy ();
ImageLoader. stop ();
}
}