I want to create app like this http://www.edumobile.org/android/wp-content/uploads/2012/08/pathfinderexample2.png http://www.edumobile.org/android/wp-content/uploads/2012/08/pathfinderexample3.png It is Possible to create gesture. in slide images with left to right and right to left.
Asked
Active
Viewed 90 times
2 Answers
0

Itzik Samara
- 2,278
- 1
- 14
- 18
-
-
the ViewPager Gallery is an Example your can use only ImageViews plus the Gestures are handled by the ViewPager itself – Itzik Samara Jul 30 '14 at 10:31
0
You may use view flipper also , I have used it in my codes to slide images in my gallery
public class Viewflip extends Activity {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private ViewFlipper vf;
private Context mContext;
private final GestureDetector detector = new GestureDetector(new MyGestureDetector());
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
mContext = this;
vf = (ViewFlipper) this.findViewById(R.id.view_flipper);
vf.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(final View view, final MotionEvent event)
{
detector.onTouchEvent(event);
return true;
}
addListenerOnButton();
}
}
public void addListenerOnButton() {
// TODO Auto-generated method stub
Spinner mySpinner=(Spinner)findViewById(R.id.spinnergallery);
addListenerOnSpinnerItemSelection();
}
View addImageView(int resId)
{
ImageView iv = new ImageView(this);
iv.setImageResource(resId);
return iv;
}
class MyGestureDetector extends SimpleOnGestureListener
{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
try
{
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,R.anim.in_from_left));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.out_to_left));
vf.showNext();
return true;
}
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) >SWIPE_THRESHOLD_VELOCITY)
{
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,R.anim.in_from_right));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.out_to_right));
vf.showPrevious();
return true;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
}
}
in_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0" />
<alpha
android:duration="500"
android:fromAlpha="0.1"
android:toAlpha="1.0" />
</set>
in_from_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="-100%p"
android:toXDelta="0" />
<alpha
android:duration="500"
android:fromAlpha="0.1"
android:toAlpha="1.0" />
</set>
out_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="-100%p" />
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.1" />
</set>
out_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="100%p" />
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.1" />
</set>

Gokul
- 164
- 1
- 11