I use CollapsingToolbarLayout in my application. On collapse or expand I fade layout inside. I disabled AppBarLayout.OnOffsetChangedListener when fading is in progress to avoid wrong behavior.
Now when I swipe fast (e.g down and up) my app ignores the second scroll and layout stays faded. When the second scroll ends I want to compare offset before and after the animation and then call callOffsetChanged() or something so it runs through onOffsetChangedListener again.
Related
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.
In my project I've setted the background color of my items (composed of several elements inserted in a ConstraintLayout) inside a ListView but the default animation of click and long click disappears if the background color is not at least a little transparent. In fact, as transparency decreases, the effect of clicking on the elements is less and less evident. In a few words, color goes to hide the animation if isn't transparent. How to solve this problem and then bring selection animation to the foreground?
Same problem, still unresolved: ListView items not showing tap animation
RESOLVED!
You have to simply add android:drawSelectorOnTop="true" in your ListView XML tag. In this way you can modify and customize the list item background and at the same time bring back the "selector" on top of the "z axis" of GUI. Yuhu!
If you are giving a background coloraturas to the list items then you might be hiding the system press animations. in this case you can use the methods like OnItemLongClickListener() and itemClickListener () and add your custom animations to the view.
I have a tabbed ViewPager which lets the user jump to the corresponding page depending on which tab they press. The problem is that you see the view pager scroll really quickly to the selected page, meaning you get small glimpses of each its scrolls through. Is there a way to stop this and jump instantly without seeing other pages.
Call setCurrentItem(itemPosition, false) on your ViewPager instance. As per the documentation the second parameter is smoothScroll effect which causes the glimpses of the other fragments.
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
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.