Android : hide/show footer/header as scrolling scrollview down/up - java

I am trying to implement a way to have my footer slide away down and my header to slide away up while user scrolls down the scrollview.
And vice-versa, as the user scrolls up the scollview, I want my footer to slide in from the bottom and the header slide in form the top.
Regarding the animation, I have found this good library https://github.com/daimajia/AndroidViewAnimations that comes with a lot of nice animations.
The closest example for what I am looking for, is the default Android Twitter application that makes it's footer disappear as the user scrolls his timeline down and makes it reappear as the user scrolls up.
By header, I am not talking about the Android Toolbar (op AppBar or whatever). It's a customed-made UI element that I want to animate while the user scrolls.
Same thing goes for the footer : it's a customed-made UI element.
While looking for solutions, I stumble upon this answer https://stackoverflow.com/a/28712465/3535408 but it does not work.
Indeed, placing a Log.d inside the ifand else if shows that a simple touch with my finger triggers both a MotionEvent.ACTION_DOWN and a MotionEvent.ACTION_UP event. The same applies as I am sliding my finger up/down making the scrollview scrolls up/down : both events are triggered at the end when I stop touching the scrollview.
Is there a way to improve this solution ? Because as of now, as both MotionEvents are triggered, both animations are also triggered so the result is quite horrible.
Thanks !

An easy way to achieve that would be the following:
place the listview, the header and the footer inside a RelativeLayout
align the header with parent's top
align the footer with parent's bottom
add an empty header and footer to the listview with the same heights
catch the scrolling events on your listview and change the footer and/or header's translationY accordingly
But to answer your question, I'd say you should try a GestureDetector. It's way easier to manage the events - Detecting Gestures

Related

animation of swipe and hide action with animation android

When the page is first opened, I want the linear layout to slide to the left and come back after a while because when I swipe, there are two different operations on the right side, I want them to appear for a short time, what can I do for this? Want to do with animation.

How to customize ItemTouchHelper in RecyclerView Android

I have a RecyclerView where I want to enable Swipe to Delete/Star on items. My item is a FrameLayout where a MaterialCardView is on the top and the revealed star and archive layouts are under it.
I already made the swipe behavior work using onTouch method applied on the CardView only, but it's just way too hard to scroll across the list or use onClick or onLongClick as onTouch overrides them. The only way to scroll the RecyclerView or invoke onClick or onLongClick is to move only in Y axis without moving even a half pixel in X, as moving in X will invoke an ACTION_MOVE event that will redirect all next touch events only to the CardView. (requestDisallowInterceptTouchEvent()) as the first statement of the switch case of ACTION_MOVE).
So I want to apply ItemTouchHelper or something similar on the CardView while having the ability to modify the way how the card X changes (To make it slower than user swiping speed like in irremovable notifications in Android) and get the MotionEvent that the user applies, and that's because ItemTouchHelper isn't very literal about what can be treated as a swipe, so it would allow onClick and onLongClick on small movements, and allow scrolling the list when the movement of Y axis is way greater than X's.
Please don't close this question saying "Too board" like a lot of other questions I had a chance to answer :(

Vertical gestures + vertical scrolling

I am currently developing a rss-reader-app and got stuck on a problem:
In a special activity i need to
swipe left/right to switch to the previous/next article
scroll up/down to scroll through the current article
build some custom gestures (For example swipe a "S" to share this article)
Is there any way to get those 3 requirements build in?
The problem is when I listen for the custom gestures either the swipe or the scroll stops working depending on the orientation of the GestureOverlayView.
I hope you understand what I mean!
Regards
Manu

Android Horizontal Scrolling that Snaps to List Items

I'd like to implement a UI experience in Android where a user can view a single item (for example, an item in my case is a collection of texts), and swipe left or right on the item to go to the previous or next item.
From my research, ListView does not implement horizontal scrolling. Potential candidates seem to be HorizontalScrollView and GridView, but I haven't seen any examples that can do this simply - only seemingly complicated libraries that need to be included.
My question is, is there a way to use ListView, HorizontalScrollView, GridView, or a combination of them to implement a horizontal scroll that shows one item at a time and snaps to the item being displayed?
The highlighted area in the picture below shows where I'm trying to implement this logic.
It looks like the best option to achieve this experience is a ViewPager, which requires the android support library.
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Keyboard hides content in fragment, I need the frame layout to resize so bottom is just above the keyboard and now scrollable

I have a fragment in my app that has a scroll view for the signup and login pages. Right now there isn't enough content in the scroll view to actually make it scroll, however when the keyboard appears, it does cover up most of the content in the view. This causes a lot of issues especially on devices with smaller screens, it blocks a lot, and the view is NOT scrollable, so I have to close the keyboard to get to the rest of the inputs.
I need the bottom of the fragments frame layout to be pushed up to JUST above the top of the keyboard, so the keyboard won't actually hide any content, and still allow the scroll view to actually scroll to the rest of the content.
I have seen the usual fix to an issue similar to this, which would to change the AndroidManifest.xml to the following:
android:windowSoftInputMode="adjustResize"
but this will push up the entire page, which includes the footer view I have under and outside of the login and signup fragment layouts. It makes my scrollview smaller and allows for it to scroll, but I need the footer to stay hidden under the keyboard still.
I think a work around to this would be to have override onConfigurationChanged(); in MyActivity that will detect if the keyboard has appeared, and if it has, push the bottom of the framelayout to be JUST above the keyboard, thus making the scroll view smaller, and allowing us to actually scroll. I am not quite sure HOW to do this though.
Here is what it looks like with the keyboard up, blocking the content. This would be okay IF the scroll view was scrollable, allowing me to see the rest of the content, however it will not scroll and the only way to access the content under it is to close the keyboard first.
EDIT
I was able to use the answer below, editing the Android manifest for
android:windowSoftInputMode="adjustResize"
and the first method using the code below
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
I had it adjust my views so the footer would be pushed way down below, then resize the layout holding the fragment to extend down allowing it to be scrollable still.
Okay, here's how I solved it.
The basic idea is that you have to:
Detect whether or not a soft-keyboard is showing,
React. Based on the detected information (is-soft-keyboard-showing), resize your layout accordingly.
There are two ways of achieving this:
to give your activity's root view a known ID, say '#+id/activityRoot', hook a GlobalLayoutListener into the ViewTreeObserver, and from there calculate the size diff between your activity's view root and the window size:
Customize your top-level layout class into one which overrides onMeasure()
And I would like to credit the above answer to this SO Post: how-to-check-visibility-of-software-keyboard-in-android, which I have found earlier on this particular problem.

Categories

Resources