How to change an image depending upon ScrollView Direction (Android) - java

Basically I want to change an image depending upon whether the user is scrolling up or down in a Scrollview.
I know how to change an image dynamically but I can't figure out how to return the direction the Scrollview is currently moving.
Thanks

This answer will help you on implementing a scroll change listener. Using the value it provides, you can determine whether it is up or down.

Related

How to detect the type of scroll and then assign the touch to vertical or the inner horizontal scroll view

I have a RecyclerView which has a several View Holders and some of them are horizontally scrolling. To improve the usability of my application, I need to detect the scroll based on angle (say 30 degrees to X axis) and depending on that, assign that to child's Horizontal scroll or let it's parent's vertical scroll handle it.
From #suragch's answer https://stackoverflow.com/a/46862320/10165076, I understood we can intercept the touch event of the parentView, but I have a hard time coding that. If you can please help me here, it would be much appreciated.
Edit: Going further deep into usability, I need this to work smoothly even when the parent view is moving with the momentum of the fling.
Of the apps that I know, the Play Store app handles this perfectly, I tried to search for a solution online, but none of them could provide an approach that works as well as the Play Store does.

Draggable overlay that can go offscreen?

I have created an overlay menu that is a rectangle.
It displays on top of everything else while active. All other apps, the home screen, etc.
If you click anywhere outside of this rectangle your click hits
whatever is visible.
If you click the red part it allows you to drag the menu around the
screen. Clicking the green part performs some function.
I have created this rectangle from inflating layout xml. The rectangle itself is a relativeLayout and the green and red parts are both imageView children.
Since I'm unable to move the relativeView off screen and since the background needs to be clickable my only solution was to calculate margins and apply them to the relative view to imitate the desired effect.
However, the code to calculate these margins is almost 50 lines and fairly complex and hard to understand at a glance if someone else needs to refactor. I can post the code but I don't believe it's relevant to the actual problem's context.
Is there a much simpler way to do this that I'm missing? Is my approach wrong?
I hope this simple project may help you Android Floating Widget

View's Properties not changing with Property Animation

I'm trying to animate a floating action button to a new location and have it be clickable there, but when I animate it via
listOptionsButton.animate().xBy(-200);
I can't click it in the new location that it goes to.
I thought that using this kind of animation would move the view itself and not just the rendered pixels.
Can someone explain what's happening and help me find a way to move my button and be able to click it at the start and end locations?
I fixed my issue. It turns out that I animated the button outside of the parent layout and even though I used property animation, the button wasn't reachable because it was outside of the bounds of the parent.
I don't know how to elaborate further, because I honestly don't fully understand why this was an issue, but I ended up making a compound view that took up my entire screen so it wasn't an issue in the end.

Draggable border to resize view

The past few months I've been on a mission to implement widget support in my home screen replacement for Android, and it's proving rather difficult. I can now add and remove widgets to/from the home screen, but they can't be resized or moved yet. Currently what I'm trying to achieve is to resize them. To do this I have every widget embedded in a View, over which I put an overlay to make sure the touch events don't get caught by the widget underneath it (which caused trouble in past attempts).
What I have now is this layout for the container; http://www.hastebin.com/uwocaxukel.xml
The widget is put in the FrameLayout with id widgetContainer. As you can see in the screenshot below there is an orange dot in the middle of every border.
Now what I've always tried to do so far is catch touch events, figure out whether the user is trying to drag one of the borders (MotionEvent.ACTION_MOVE), and if he is, change the required properties in the LayoutParams object and call this.requestLayout () on the view. This is finicky, and less than ideal. Very often the touch events would stop registering because the user dragged faster than the view could refresh = user is no longer on the view which is listening for touch events, or the border would be too thin to hit.
So far it's all been very finicky. But there are other apps which seem to do this pretty much perfectly. Is there a library, a class I've overlooked, or something else I can use to achieve my goal?
This is an example of something that kind of worked, but was very finicky and just not remotely user-friendly; https://github.com/RobinJ1995/be.robinj.ubuntu/blob/869d48af2e7a3d8f0332f84edd2a8cd28564424a/UbuntuLauncher/app/src/main/java/be/robinj/ubuntu/widgets/WidgetHostView.java#L75

Eclipse android widget moving

I am designing my activity screen using eclipse but whenever I move an object e.g. a button it snaps around and I find it hard to position things where i want them.
Is there some setting I can change as as soon as I add a second button it snaps the other button to another position it is so annoying!
Also if I have an image button why can't i resize this, even with a normal button if i try to make it larger it just fits to the text and wont make the button bigger or it just flicks to a random place on the activity?
thanks
Probably you're trying to place components freely in the View but you're not considering the LayoutManager behavior. If you try to position your component in a LinearLayout, for example, the components will be placed following its rules, and these components will not stay where you drop them.
Try to understand better how the layouts works on Android. But for now, the AbsoluteLayout or RelativeLayout may be what you're looking for.
About the components size, you'll need to understand better how to use layout properties for these components. See the question How to size buttons for more information.

Categories