I am developing an android application in which I want to slide images with finger touch. I have implemented an onClickListener
with which I can slide images but I
You can use the Gallery widget
Here the link to the API
There is also a tutorial. For me it was very helpful :)
You can use onTouchListner method instead of onClickListner. Below onTouchListners example is given..
public class abc extends Activity implements OnTouchListener
{
ImageView img;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.one);
img = (ImageView) findViewById(R.id.imageView1);
img.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
// Here u can write code which is executed after the user touch on the screen
break;
}
case MotionEvent.ACTION_UP:
{
// Here u can write code which is executed after the user release the touch on the screen
break;
}
case MotionEvent.ACTION_MOVE:
{
// Here u can write code which is executed when user move the finger on the screen
break;
}
}
return true;
}
I would really suggest you using RealViewSwitcher class by Marc Reichelt, get it from here It provides a slight view swticher, like android launcher does.
Views can catch touch events -- take a look at OnTouchEvent which lets you catch MotionEvents like touch down and touch up. You could use a handler to loop, moving the image/view to the currently touched place after a touch down event until a touch up event.
What you are looking for is an ViewFlipper
. This will help you to get the look what you are expecting.
This mgiht be helpful
check this too
Or try this,
In your xml just add only this,
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ViewFlipper>
need not enclose with any ImageViews.
Now do this in your coding.
Considering that you have stored your Images in a array like this,
int gallery_grid_Images[]={R.drawable.gallery_image_1,R.drawable.gallery_image_2,R.drawable.gallery_image_3,
R.drawable.gallery_image_4,R.drawable.gallery_image_5,R.drawable.gallery_image_6,R.drawable.gallery_image_7,
R.drawable.gallery_image_8,R.drawable.gallery_image_9,R.drawable.gallery_image_10
};
Now in your onCreate(),
viewFlipper = (ViewFlipper) findViewById(R.id.flipper);
for(int i=0;i<gallery_grid_Images.length;i++)
{
// This will create dynamic image view and add them to ViewFlipper
setFlipperImage(gallery_grid_Images[i]);
}
And now add this method to your activity,
private void setFlipperImage(int res) {
Log.i("Set Filpper Called", res+"");
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(res);
viewFlipper.addView(image);
}
That's it. And now using your viewFlipper.showNext();
and viewFlipper.showPrevious();
methods you can show your dynamic images.