My viewFlipper contains 15 LinearLayout.
After it reaches, I have a button "Back to menu".
I've used
showNext()
all the way to the 15th LinearLayout.
And now I want it to go back to 1st LinearLayout.
Anyone have any idea? How to bring it back to 1st Linearlayout?
Thanks.
Call showNext(). Or, call setDisplayedChild(0).
I used this code.
private ViewFlipper vf;
private float lastX;
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
vf.setInAnimation(this, R.anim.in_from_left);
vf.setOutAnimation(this, R.anim.out_to_right);
vf.showNext();
}
if (lastX > currentX) {
vf.setInAnimation(this, R.anim.in_from_right);
vf.setOutAnimation(this, R.anim.out_to_left);
vf.showPrevious();
}
break;
}
Related
I have a list view and I want to make it so I can swipe each item to reveal a delete button:
I've figured out how to recognise the swipe event, I am using this code (listItem is of type View):
listItem.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
_xSwipe1 = event.getX();
break;
case MotionEvent.ACTION_UP:
_xSwipe2 = event.getX();
float deltaX = _xSwipe2 - _xSwipe1;
if (deltaX < 0)
{
Log.e("SWIPE", "Right to Left swipe");
}
else if (deltaX >0)
{
Log.e("SWIPE", "Left to right swipe");
}
break;
}
return false;
}
});
And when I swipe, I can see in the logs that the swipe event is being recognised.
However, I'm not sure how to physically make the list item start disappearing to the left?
Any help would be greatly appreciated.
If you know when the swipe is happening and how much the user has swiped you could call View.setTranslationX() depending on how much the user has swiped. Alternatively, you could forego the swipe detection logic altogether and use a ViewPager with only 2 pages. You would then override PagerAdapter.getPageWidth(...) in your PagerAdapter so that the delete button only takes up a limited amount of space.
I have a view flipper containing two layouts with button. Now the issue is i am not able to swipe along with finger. Basically the view should swipe along with the finger. I hope you are getting what i am trying to say. Here is the onTouchevent code :-
bottomFormatFlipper = (ViewFlipper)findViewById(R.id.bottomFormatFlipper);
public boolean onTouchEvent(MotionEvent touchevent)
{
switch (touchevent.getAction())
{
// when user first touches the screen to swap
case MotionEvent.ACTION_DOWN:
{
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
// if left to right swipe on screen
if (lastX < currentX)
{
// If no more View/Child to flip
if (bottomFormatFlipper.getDisplayedChild() == 0)
break;
// set the required Animation type to ViewFlipper
// The Next screen will come in form Left and current Screen will go OUT from Right
bottomFormatFlipper.setInAnimation(this, R.anim.in_from_left);
bottomFormatFlipper.setOutAnimation(this, R.anim.out_to_right);
// Show the next Screen
bottomFormatFlipper.showNext();
}
// if right to left swipe on screen
if (lastX > currentX)
{
if (bottomFormatFlipper.getDisplayedChild() == 1)
break;
// set the required Animation type to ViewFlipper
// The Next screen will come in form Right and current Screen will go OUT from Left
bottomFormatFlipper.setInAnimation(this, R.anim.in_from_right);
bottomFormatFlipper.setOutAnimation(this, R.anim.out_to_left);
// Show The Previous Screen
bottomFormatFlipper.showPrevious();
}
break;
}
}
return false;
}
From this code, when i swipe, then after a second or so, the swipe animation occurs. I want that the view should swipe with my finger
I'm looking for help with creating ViewFlipper which will work like in android calendar when switching between months by swipe.
I want to have only two views inside my viewFlipper, and when i swipe right i want to do
mViewFlipper.setDisplayedChild( 1 );
and when i swipe left :
mViewFlipper.setDisplayedChild( 0 );
and when i swipe twice left, i want to get every time full in/out animation and the same for right swipping. Full animation works only when i swipe to next and to previous, never in direction of next -> next.
Thanks for help!
If you're only using 2 views, and at present and you're setting 0 and 1 manually as such, just call
mViewFlipper.showNext();
instead regardless of the swipe direction and apply the correct animation depending on if you want it to be sliding left or right. This will mean even if you're on view 1 and you slide right again (like you defined) then view 0 will come back in, like a never ending flipper between the 2 views.
http://developer.android.com/reference/android/view/animation/AnimationUtils.html
I may be totally misunderstanding your question however, it is rather vague.
See this link it may help.....
http://www.1mobile.com/effective-navigation-863044.html
http://developer.android.com/training/implementing-navigation/index.html
**folder in res = animator.......
translation animation xml file = s_in_fleft in animator folder in res folder.....
might help**
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
if (viewFlipper.getDisplayedChild() == 0)
break;
viewFlipper.setInAnimation(this, R.animator.s_in_fleft);
viewFlipper.setOutAnimation(this, R.animator.s_out_right);
viewFlipper.showNext();
}
if (lastX > currentX) {
if (viewFlipper.getDisplayedChild() == 1)
break;
viewFlipper.setInAnimation(this, R.animator.s_in_fright);
viewFlipper.setOutAnimation(this, R.animator.s_out_left);
viewFlipper.showPrevious();
}
break;
}
}
return false;
}
I am using the following method of flipping images: How to set dymanic images to ViewFlipper in android?
I do not want to flip using buttons. When the user touches the images or swipes the image I want to flip to the next image. Is there a way I can achieve this?
You can use ViewPager. See these links:
Implementing Horizontal View Swiping Using ViewPager and FragmentPagerAdapter in Android
Horizontal View Swiping with ViewPager, Updated
Android Viewpager as Image Slide Gallery (Swipe Gallery)
and this Library
Support Library
this might Help..... animator is a folder in res and the s_out_* is an xml file with a translate
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
if (viewFlipper.getDisplayedChild() == 0)
break;
viewFlipper.setInAnimation(this, R.animator.s_in_fleft);
viewFlipper.setOutAnimation(this, R.animator.s_out_right);
viewFlipper.showNext();
}
if (lastX > currentX) {
if (viewFlipper.getDisplayedChild() == 1)
break;
viewFlipper.setInAnimation(this, R.animator.s_in_fright);
viewFlipper.setOutAnimation(this, R.animator.s_out_left);
viewFlipper.showPrevious();
}
break;
}
}
return false;
}
Hie all ,
is there any method in android that can differentiate the left and the right scrolling actions in android.
it is actually a customized gallery view so what I am trying to do is that on scroll actions i want to different images. I mean on left scroll I've different images and on right scroll I've different images to show. so i need to differentiate the let and right scroll.
Try this code:
new OnTouchListener() {
#Override
public boolean onTouch(View currentView, MotionEvent touchevent) {
switch (touchevent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
if((oldTouchValue - currentX) < 50 && (oldTouchValue - currentX) > -50) {
return false;
}
if (oldTouchValue < currentX)
{
// Left swipe...
}
if (oldTouchValue > currentX)
{
// Right swipe
}
break;
}
}
return false;
}
}