Pass click event through levels of ScrollViews and Layouts - java

I have many ScrollViews with RelativeLayouts inside in one Activity all of them cover the whole screen. I got buttons in some of them but the problem is the top layout is blocking the click events for the other layouts.
I want it so if no button is hit at the first layout it passes the click event to next etc.
You may wonder why i have many layouts that covers the whole screen and that is because i got scrollviews in them to create a 3D paralax effect scrolling background with different layers.
On the top layer also have setOnDragListener if that is important.
Here i will try to show you how my setup is:
HorizontalScrollView1--Layout1--Images/Buttons
HorizontalScrollView2--Layout2--Images/Buttons
HorizontalScrollView3--Layout3--Images/Buttons
So right now ScrollView3 is taking all clicks because its in the front/top. I can't disable clicks on the Scroll cut it needs to be scrollable and there is also buttons at the top layer that needs to be clickable.

overriding this in the relativelayout and returning true makes the above routine redundant:
RelativeLayout slideLayout=new RelativeLayout(mContext){
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mIsMuteTouches) return true;
return super.onInterceptTouchEvent(ev);
}
};

Related

SwipeRefreshLayout block android.wiget.swith from dragging

I have an activity and 10 fragments which I draw on activity. All fragments on activity need to have "drag to refresh". I add Swipe Refresh Layout to create it. Now when I click on the switch, all is fine; but when I try to drag it from one stage to another, swipe to refresh appears, and the switch is just staying in the same position. So how can I block the refreshing of the swipe refresh layout on time when the user drags the switch from one position to another?
I tried to make it like this:
onOffSwitchSettings.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
((MainActivity) getActivity()).swipeContainer.setRefreshing(false);
return false;
}
});
But how can I turn it on after?
According to SwipeRefreshLayout reference:
The SwipeRefreshLayout will notify the listener each and every time
the gesture is completed again; the listener is responsible for
correctly determining when to actually initiate a refresh of its
content. If the listener determines there should not be a refresh, it
must call setRefreshing(false) to cancel any visual indication of a
refresh. If an activity wishes to show just the progress animation, it
should call setRefreshing(true). To disable the gesture and progress
animation, call setEnabled(false) on the view.
You've forgotten to use ((MainActivity)getActivity()).swipeContainer.setEnabled(fals‌​e) method.
Another problem is that using above you're going to disable SRL permanently, so you need to enable it again when the action is right, I mean there's no more dragging.
Hope it will help

Imagebutton one on top of another can't click the one underneath the other - Scene2d LIBGDX

I have two ImageButtons one on top of the other. Depending on events in my game I fadeOut one of the buttons and fadeIn the other, and vice versa. The problem is that the buttons are placed in a Stack at exactly the same position and the button underneath does not receive the click event. How can I temporarily stack it on top of the other one that is fadedOut so it receives the click event?
You can use the toFront() method of Actor. Then it should receive the events.

Horizontal Scrollview with snap effect

I need a widget that functions as a horizontal scrollview, but snaps to the nearest value when scrolled (it should snap from value to value, and not be possible to stop the scrolling in between values). Theoretically I would solve this with a viewpager with negative margins - so that all the views are simultaneously visible, but it also "snaps". But I have a problem - if I use a viewpager then only the "foreground" (i.e. currentView) view is "clickable", and I need all onscreen visible views to be clickable at any given time. So - is there any way of having a "snapping" horizontal scroll widget where all visible views are clickable?
For example, the screen might look like this:
A B C D E
where scrolling right reveals F, G, H..
initial state should allow clicking on any of A,B,C,D,E and not just on A (if it was the "currentview")
You can use Snap ScrollView library. It supports both horizontal and vertical snap scrolling. You can add views directly. Click on this SnapScrollView library
And regarding click, you can implement onClick listener for each view and call correspondingly.

ListView: Scroll to an item at the top of the ListView (and keep it there)?

I have a ListView with a significant number of items on it. I would like to figure out a way to get it to scroll to a certain position, but have that position be at the very top of the view.
The other issue is that the ListView gets invalidated and re-drawn at some point after this happens and I need it to return to this position when it is re-drawn.
I have tried smoothScrollToPosition, but this only brings the item into the view, and does not place it at the top. I have tried scrollTo(x,y) but I don't know the exact y-position of the item in the view. I have tried setSelection and setSelectionFromTop, but the selection gets reset when the view is invalidated. I have also tried all of these things within a post(Runnable) call, with no luck.
Here is the solution I have at the moment, which is awful.
listView.post(new Runnable() {
#Override
public void run() {
listView.smoothScrollToPosition(10000);
listView.smoothScrollToPosition(pos);
}
});
This forces it to scroll down to the bottom and scroll back up until the item at the specified position comes into the view, which has the effect of placing it at the top. Fortunately, the animation only goes so far as to scroll from the top to the end position, so it doesn't actually play out scrolling to the bottom and then back up. However, this solution is slow, hacky, and just generally awful. Does anyone have a better one?

Libgdx : setting another screen, but still buttons from old screen active

In my libgdx game, I have 2 screens, menu and list.
When I click on a label in the menu screen, I do a setscreen(list).
The new screen shows up, and the menu screen alongwith its labels disappears.
But when I click on the same positions (from menu screen where the labels were, but of course those labels are not showing as I have changed screens) the click event responds. Why?
note:My list screen currently has not event handlers for any widget.
When switching screens do I need to do anything more than just setscreen(anotherscreen) to deactivate oldscreen?
I changed this :
I moved the input processor to the show() method of that screen using stage variable of that screen
public void show() {
...
Gdx.input.setInputProcessor(stage);
}
before I was setting this only in the constructor of the screen, so even If I was changing the screen, the input processor was still attached to the last created screen's stage
The answer above adiddnt work for me because I dont work with a InputProcessor in the 2nd screen.
My Solution was to set the Inputprocessor to null after setScreen.
Gdx.app.getApplicationListener().setScreen(new Screen());
Gdx.input.setInputProcessor(null);
Just broke my head over this. I changed screens in the show method but had Gdx.input.setInputProcessor(stage) called after that. The method still completed after the show method of the new screen ran and thus reverting back to the previous stage.
So make sure you call Gdx.input.setInputProcessor(stage) before you change screens or return after you change screens.

Categories