I am trying to pan a RelativeLayout with child Views, using gesture onScroll event, but I do not get the result that I desire. I have tried to move the children, but nothing works.
Any suggestions?
Related
I'm currently working on a project where I have a custom view (graph). It is located inside a RecyclerView which is inside a NestedScrollView. My GraphView has an onTouch event that allows to see additional info while you're dragging your finger over values. When I was initially trying to implement it I would frequently receive an ACTION_CANCEL which was due to parent view interfering with its scrolling. After that I found a hacky solution which was to disable the parent controls at all with requestDisallowInterceptTouchEvent(true).
But this solution isn't exactly what I'm looking for. Instead I would want my app to have both at the same time. So, basically, custom view would keep showing additional data and have its onTouchEvent() triggered but my RecyclerView or NestedScrollView would still be scrolling if it received a drag by y axis.
Is it possible to implement this kind of a behavior and what would I need to do exactly?
I have nested ViewPagers and RecyclerViews as depicted in the image:
Requirements:
The first level ViewPager1 swipes from left to right. It uses FragmentStatePagerAdapter.
The first level RecyclerView1 scrolls vertically.
The second level ViewPager2 does not swipe - the swipe motion is controlled by a TabLayout. It uses a custom PagerAdapter that returns a View as a page.
The second level RecyclerView does not scroll - it simply wraps a list of dynamic items
What I have working so far:
The first level ViewPager1 and RecyclerView1 works as intended.
The ViewPager2 does not show because its height is defined as "wrap_content"
The ViewPager2/RecyclerView2 prevents RecyclerView1 to scroll up/down.
What I have tried:
Setting RecyclerView1.setNestedScrollingEnabled(false) stops it from passing the onTouch event to its children, but because the ViewPager2/RecyclerView2 wraps its content, it does not know what the size it needs to scroll.
Setting the ViewPager2 to a fixed height solves the scrolling problem. But because it is a fixed height, the content of RecyclerView2 is cut off.
Overriding OnMeasure as described here makes ViewPager2's content wrap, perfectly, but the scrolling no longer work again. I assume it is because OnMeasure is called "after" the View has already been attached?
So basically I need help on how to get the content to wrap but in such a way that RecyclerView 1 knows what the height is so that it can scroll.
EDIT
It turns out I was totally off base with point 3. The OnMeasure workaround DOES work as intended and the scrolling problem is NOT caused by recyclerView not knowing the height. It in fact does. The reason why it doesn't scroll is due to multiple nested scrollable view groups. I found this out by putting Log.i on onTouchEvent() and onInterceptTouchEvent() on all the scrollable view groups. Some surface of the views work, but if the surface has another scrollable child, it starts to cause problems.
Setting RecyclerView2.setNestedScrollingEnabled(false) fixed the vertical scrolling. However, now, the ViewPager2's touch behaviour is interfering with ViewPager1's
On closer inspection, ViewPager1 intercepts touch event when hitting non-scrollable surface, causing the ViewPager1 to call its onTouchEvent() to scroll left and right. However, if I start the touch event over a the ViewPager2's surface, ViewPager1 never intercept and it never handles the swipe left to right.
Unlike a RecyclerView, there is no simple method to disable nestedScrolling. So I tried disabling ViewPager2, but that didn't work and caused the inside views such as buttons not clickable.
I tried to return false in ViewPager2's OnTouchEvent so that it bubbles up the chain, but still, the ViewPager1's OnTouchEvent is never fired.
So I'm stuck again, how do I pass the touch event to the parent when the parent did not intercept the event when it should have. Again, I'm assuming, and again I might be off-base, that ViewPager1 might not intercept because ViewPager2 has requested a disallowInterceptTouchEvent() somewhere in its code? I just don't know where or how to begin to fix this problem.
I have an Android app with an Activity that I'd like to be able to pinch zoom.
The Activity is a LinearLayout that contains several controls, one of which is a ScrollView. I've implemented the zooming by following the very good example here:
https://github.com/Xjasz/AndroidZoomableViewGroup/blob/master/ZoomListView.java
Here's what I've seen:
If I put Finger1 outside of the ScrollView, I can put Finger2 anywhere and things zoom beautifully.
If I put Finger1 inside of the ScrollView, then nothing will zoom regardless of where I put Finger2.
It seems to me that once a finger goes into the ScrollView, the onTouchEvent is not propagated up to the parents.
Has anyone else seen behavior like this? Any ideas on how I can fix this so that I can always zoom if I touch inside the ScrollView first?
I am using two (embedded) ScrollViews like suggested here, in order to create a '2D Scrollview'.
I add multiple childs to this view, and to some of them I set OnClickListener (I also tried with OnLongClickListener as well).
Functionally the result is what I have expected, although if I try to scroll (starting from a child, that has either of the listeners), the scrollview jumps/repositions to the ~opposite direction, I started the scroll to. So if I scroll like this e.g. upwards, the view jumps a big downwards so that I can scroll up at most to the original position.
I have been trying to play around with calling setFocusable(false) on the childs and setFocusable(true) on the ScrollView(s) (but also tried different permutations of it, as I am not sure about setFocusable()), but couldn't really get on top of it.. Any suggestions?
Just encase you are still wondering this is happening because when you start scrolling the other scroll view, ACTION_CANCEL is posted to the on touch method of the original ScrollView which causes a default scroll view to jump back to its original position.
Hi I have a horizontal scrollView and inside it I draw some arcs on canvas which gives me set of horizontally scrollable pie charts. Now I need to handle the on click events of each of the pie charts, could some one help me regarding the same.
ChartUtility sampleObject=new ChartUtility(getActivity());
sampleObject.draw(new Canvas());
ChartContainerLayout.addView(sampleViewObject);//here chartcontainerlayout is a linear layout which his present in a horizontal scrollview.
I have tried the ontouch event of chartutility class. But what ever is the action(either a click/horizontal scroll), the event.ACTION is being returned as "down". So how should I recognize the click event on individual items.
I would put a LinearLayout with orientation set to horizontal into the HorizontalScrollView and then make each pie chart in a separate layout within that. Then set listeners on those layouts. I would not have the click handling mixed with the scrolling.