Here's the idea: I have some ScrollView, e.g. with 10 elements, say buttons.
Only 5 are visible at the time.
By default, if I swipe up a little bit (30% of next element's height), app will show me 30% of 6th item, and hide 30% of 1st item at the top.
I would like to customize this behavior, so that it pulls up a new element from below only after I've swiped up for more than a half of that elements height.
If I swipe just a little, it disregards scrolling and hides back the element that could've been shown if I swiped more.
Sadly, I can't remember an app to point as an example. The nearest is pulling NavigationDrawer (or sliding home screens in your launcher): if you slide only a little and release - it hides everything back.
Additionally, I would animate showing that new element (e.g. scaling from 0 to 100) and hiding the one on top that is being hid (scaling from 100 to 0). But that's second issue, I'd rather think of it when I deal with this threshold of scrolling.
Has anyone heard about some kind of library for this? I would expect that to be in API, but it's not there, AFAIK.
Related
[Sliding left takes to next page of results and sliding right takes to prev page of results (of the same search), dashes at the bottom shows the page position please look into the png]
https://i.stack.imgur.com/fyxac.png
If you know the number of elements per screen, you can use LinearLayout and add the elements to it at runtime. You anyway won't be recycling views if there is no scroll.
Even if you don't know the number of elements per screen, the next best thing to would be to calculate the number of elements you can completely fit by dividing the left over screen size by the size of one element.
For horizontal pages, you can make use of ViewPager.
I succesfully implemented RecyclerView using StaggeredLayoutManager with 2 col/spans. I have variable heighted items in each col, heights are not fixed.
Problem is, when I scroll down and up in RecyclerView, sometimes a gap is occured at the top item of one of the rows. I added a video describing my problem.
I simply added a StaggeredLayout with span value 2, and adapted my items with an adapter.
+-+-+-+-+-+-+-+-+-+-+-+-+ <------ Top of RecyclerView
-------------- <- Top item in left column
------------- <- Top item in right column, has unexpected gap/offset/margin at top.
Gap sometimes occurs. Sometimes, everything is well aligned and no problems.
Here is the video I take from my application.
https://youtu.be/gmB7h73YR3M
Look at the topmost 2 pictures(LinearLayouts) in the list, cup and monitor. Their top position differs after each scroll down and then up event, and an unwanted grey area (Backgroundcolor of RecyclerView) appears at there.
Between 0-3 sec, there is a gap on top of cup, left column.
Between 7-8, there is a gap but little than 0-3
Between 10-12, everything is fine, their tops are at same level.
Between 19-21, this time right column has a gap on top.
Any reasons why I have this problem, any solutions?
EDIT:
Because I don't want so much moving items, I set gapping strategy as GAP_HANDLING_NONE. However, when I set strategy as GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS, toppest line of two items get aligned when Scrolling Up ends at top. My observation is, when scrolling to the elements at top, a last calculation is made to Align top lines of 2 items if strategy is GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS, but not in GAP_HANDLING_NONE. I can see it is aligned with my eyes, but it doesn't seem to happen when strategy is GAP_HANDLING_NONE.
What should I do to partially hide some layout from code? Should I play with setMargins?
Basically, I want to detect size of the screen and then I want that element X becomes visible only 10% of its width? I know how to do it all except how to make it partially hidden or offscreen?
Look at these images to see what I want to achieve. Image 1 - UI element is in the center. Image 2 - I set in code it's moved to top offscreen thus becoming only partially visible.
I found out that here as well the best solution is to use Animation (TranslateAnimation) by setting this on the first screen load and setting its speed to minimum value of 1 millisecond. The transition in reality is unnoticeable to a human eye.
Also do not use margins as they simply "push" element from one side without making it goes offset. If you have any child in the layout you want to offset, they all will be squeezed as you increase margin values.
NOTE: if you ever want to use animation on that screen on the element you offset before, take into account the negative value of offset. Otherwise your animation will not look nice. To avoid bumping effect, take special care of fromXDelta value.
I am aware that I should decide how many pixels based on density.. not hard coded.
I have section headers and items displayed in a scrollview and I want to scroll to a certain section header (the one for the current date) while making it clear that it is not the top of the screen (show about half of the previous item).
How can I do that? I do not want this automatic scroll to be animated.
With View.requestRectangleOnScreen() you can scroll to show a particular rectangle (the linked method allows disabling animation). You still will have to calculate that rectangle, but once you have the position of the particular child (your header) you can easily do that getting the size of the ScrollView. You could consider the small offset you want in calculating that rectangle or just do a scrollBy() after requestRec....() (the former way is better I think).
An easy way to use a density independent dimension is to define it in xml as a dimension resource.
-- edit: you get the position of the child in parent with getLeft() / getTop().
This might be a "duh" question but I'm going to go ahead and ask it anyway.
I have an oversized (bigger than the screen) RelativeLayout, and I'm using swipes to start a TranslateAnimation from viewing one part of the layout to another. Say for instance the layout is two screen wide and two screens tall. After the nice animation to shift the screen, I was using View.scrollTo() to set the new position. This works fine going from the first screen (top left at 0,0) to one of the others. When I swipe to animate back to the first screen though, because the View.scrollTo() invalidated that part of the layout (I assume), that part of the layout is all black as I animate through it. I tried a couple things to get it to redraw itself after the scrollTo() but haven't had any luck, so I figured I'd ask here.
thanks!
joe d
I can't help with your specific problem since I've never tried working with a layout bigger than the screen, but there might be another way to achieve what you're trying to do. If you simply want to be able to finger-swipe from one View to another, without ever displaying part of one screen and part of another (i.e. you aren't smoothly panning around a large View but rather just jumping from one distinct section of the layout to another), then these tutorials might help, here and here. They show you how to use touch events and the ViewFlipper widget to change between Views using animations.