Unclear MotionLayout parameters - android

Could anyone please explain what MotionLayout's onSwipe parameters touchAnchorId and touchAnchorSide do? This is what documentation says about touchAnchorId
View that is being moved by the swipe.
That doesn't make sense to me as swiping on MotionLayout doesn't move a single view. Swiping progresses transition between starting constraintSet and ending constraintSet. I thought initially that touchAnchorId would specify a view that user will have to drag to progress animation but this isn't a case and MotionLayout developer team introduced touchRegionId parameter for that. It's also unclear to me what touchAnchorSide is supposed to do as I don't see any difference when changing its value.

onSwipe Move progress from 0 to 1 along a
direction(dragDirection=) horizontal (dragRight/Left/StartEnd) or vertical (dragUp/Down)
If I drag my finger a 100 pixels along the screen how much does it move from 0 to 1?
That is the main question most of the other argument answer.
with out an anchor it uses the full length of the layout.
But if you are making a pull out draw that is excessive.
You could adjust it with dragScale. But how much? The pull may vary based on constraints fonts many things.
Many times you want it to act as if you are pulling a view or a side of a view. In which case you ned to the View (touchAnchorId) and the side of the view (touchAnchorSide)
Sometimes you want to limit the region in which the swipe will work
In which case you can use limitBoundsTo.
Much of the rest of the flags are bout what to do when you lift your finger.
There is much more subtly in all the use-cases it is designed to support.

Related

how to put elements in fixed positions in a ScrollView

I want to create a kind of scroll view that its elements are fixed in the middle of the view and the user needs to move the element a considerable amount or the view bounces back to the middle of the view.
I tried to use several overscrolls next to each other and create a bounce effect but the result wasn't pretty.
is there any library for this kind of scroll view? or there is any way to do this?
If I understand this correctly, you have a fixed element fixed in the middle of the viewport. You want the user to move the element some fixed amount, say X.
If moved less than X, it should go back to the middle of the viewport?
If yes, then you should definitely look into http://bouncejs.com.
Also, this might interest/help you: https://scrollmagic.io/examples/

setX, setTranslationX, setLeft, LayoutParam.leftMargin, Matrix.. What's the difference

Another questions about setting position of a view. If you want to move a view around then you can do setX, setTranslationX, setLeft or LayoutParam.leftMargin
Offcourse there is also overriding the onDraw method and using Matrix/Bitmap/Canvas operation.
I was wondering what's the difference. Do they all ultimetly adjust the same value which is x coordinate of the view?
It would be good to have it all in one post for future readers as well
So far I know,
LayoutParam.LeftMargin: is available for all API (specific under Api
8)
SetTranslation: Difference between original left bound of the view and the new leftbound. Though I heard maybe it is not persistent?
Anyone can shed light on the differences and if they impact different properties or the same property?
I believe that the main difference between setLeft and setX() is that setLeft() is relative to its parent view, where setX() just sets the position relative to the whole screen, which is the same as setTranslationX().
In setLeft() terms it means that the layout system can change its layout position. For example if we would use setLeft while scrolling through a RecyclerView the system would change its position accordingly, so the proper use in this case would be setX().

Rotated (not animated) views in XML pre-honeycomb?

Is it possible to rotate views in XML with APIs previous to Honeycomb - maybe with the support package? Or is the only way to create a custom class, like described here Vertical (rotated) label in Android
Edit: What I need is a statically rotated view (specifically a TextView, but I guess it's enough to know how to do it with a View). Starting with honeycomb there's a rotation attribute which can be used in XML. I need something like that.
The only thing I have found until now is use an animation with duration 0 but this still moves a bit at start and I don't want that. I tried setting the views invisible and attaching a listener to the animation which makes them visible on animation finished callback, but that made strange results... that changed the position of the views, for some reason.
The best way is with the custom subclass implementation that you linked to, where you can rotate the canvas and resize the view appropriately. This ensures that the view bounds are also set to match the text that is drawn.
The only method of transforming views externally prior to HC is the animation framework, and applying an Animation to the view with a duration of 0 and fillAfter set to true will work, but you may notice flickering on some devices as often the view will render normally on its first frame and then animated to its final position from that point onward. You can work around this by hiding the view and displaying it a bit late...but you can see how hacks are starting to stack up.
In addition, doing an Animation prior to HC will not transform the view bounds themselves, so you won't be able to neatly pack other views around this one because its position from a layout perspective will still be the rectangle calculated for the horizontal (non-rotated) text.
The simple subclass is definitely the preferred method.
HTH
Is it possible to rotate views in XML with APIs previous to Honeycomb
There is RotateAnimation. However, depending on what you are trying to accomplish, that may not meet your needs.

Android custom zoom animation poor performance

I have a bit specific problem, but hopefully someone will chime in and help.
I've written a custom zoom animation (posting runnables that change the target view to a handler between certain amount of time) but when i change the view's width and height it is as if I've performed a zoom around (0,0) of the view whereas I want to zoom around its center so I move the view by changing its margins accordingly. The thing is though that when the zoom iteration step is too small (i.e 0.01f and less) I have to change the margins of the view by something like 1px sometimes only in one of the directions which makes it look as if the animation is glitchy. I'm not sure of the exact reason but I've tried the following things:
1) I tried changing the margins by overriding onLayout() of my parent view which will be caled when setting the layoutParams upon zooming( I did this in order to avoid a second call to setLayoutParams() upon moving which actually now doesn't seem quite reasonable since setLayoutParams() just sets some flag which will be used later on).
2) I'm checking the new margins to set so that they are set only when there's a difference between the new and the old margins in both X and Y directions.
3)I tried using view.offsetLeftAndRight() view.offsetTopAndBottom() instead of changing the layout params in order to move the view, but it was again to no avail.
Any suggestions what will do the trick?
If I undestand you correctly you need to get Bitmap cache from view and draw it manually. In this case bitmap will be drawn without glitches (if Bitmap filtering is on).
You can do it in following steps:
get view cache - through View.getDrawingCache or by calling View.draw function
hide view
get current system time - SystemClock.elapsedRealtime (thanks to this you can calculate animation progress)
start posting runnables to invalidate your screen and check whether animation is ended
show view
Possibly it can be done via Android Animation class but I do not use it as it quite limited.

How to "scroll" a view of indeterminate size?

I have written a custom View which is used to display a tileable pattern, and want the user to be able to zoom in (which I've got covered) and then move around within the pattern.
Because the pattern is tileable it means that there are effectively no bounds on it. In theory a user could just keep scrolling left (right, up, or down) forever. In reality I would be using a modulus to adjust the virtual position.
I'm just not sure where to start. Would I use something with scrollbars? I'm not sure that makes any sense, because as I said the viewable area is effectively infinite.
Thanks for any suggestions!
I'd use a scrollview with the scrollbars turned off.
android:scrollbars="none"
I decided a scrollview was unnecessary. All I really had to do was handle the touch events and then adjust the virtual coordinates accordingly.

Categories

Resources