android-touch-event

ViewPager2 with horizontal scrollView inside

柔情痞子 提交于 2020-08-25 07:02:29
问题 I implemented the new ViewPager for my project. The viewPager2 contains a list of fragment private class ViewPagerAdapter extends FragmentStateAdapter { private ArrayList<Integer> classifiedIds; ViewPagerAdapter(@NonNull Fragment fragment, final ArrayList<Integer> classifiedIds) { super(fragment); this.classifiedIds = classifiedIds; } @NonNull @Override public Fragment createFragment(int position) { return DetailsFragment.newInstance(classifiedIds.get(position)); } @Override public int

Handle Touch Event on both segments of the screen simultaneously

那年仲夏 提交于 2020-08-10 19:24:26
问题 So I have a touch event and it handles ACTION_DOWN and ACTION_UP one by one. For example if I click on the left half of the screen ACTION_DOWN works but not ACTION_UP and same for the right side of the screen. i want to handle both of them simultaneously. If I click on left side and right side at the same time both the event should perform. Can anyone please help me on this. My code is @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent

Fragments in ViewPager2 does not respond to clicks if scroll position is 0

筅森魡賤 提交于 2020-07-19 05:25:12
问题 I am very glad that Google released ViewPager2 which is built on RecyclerView to solve a lot of issues that the old ViewPager has. I quickly replaced my old ViewPager codes to ViewPager2: Replace ViewPager with ViewPager2 in xml Replace FragmentPagerAdapter(FragmentManager) with FragmentStateAdapter(Fragment) ViewPager setup is as below: viewPager.adapter = fragmentAdapter val mediator = TabLayoutMediator(tabLayout, viewPager, true) { tab, position -> tab.text = fragmentAdapter.tabNames

How to invoke drag event of a custom view inside SurfaceView?

↘锁芯ラ 提交于 2019-12-24 06:48:09
问题 How can i drag a custom view inside the SurfaceView. Touch events are not dispatched to child custom view from SurfaceView or child view's onTouchEvent is not called. 回答1: Try this code public class MoveViewTouchListener implements View.OnTouchListener { private GestureDetector mGestureDetector; private View mView; public MoveViewTouchListener(View view) { mGestureDetector = new GestureDetector(view.getContext(), mGestureListener); mView = view; } @Override public boolean onTouch(View v,

How to invoke drag event of a custom view inside SurfaceView?

﹥>﹥吖頭↗ 提交于 2019-12-24 06:47:16
问题 How can i drag a custom view inside the SurfaceView. Touch events are not dispatched to child custom view from SurfaceView or child view's onTouchEvent is not called. 回答1: Try this code public class MoveViewTouchListener implements View.OnTouchListener { private GestureDetector mGestureDetector; private View mView; public MoveViewTouchListener(View view) { mGestureDetector = new GestureDetector(view.getContext(), mGestureListener); mView = view; } @Override public boolean onTouch(View v,

Recyclerview: listen to padding click events

只愿长相守 提交于 2019-12-23 06:59:21
问题 I have an horizontal RecyclerView with leftPadding = 48dp , topPadding = 24dp and clipToPadding = false . It starts with an empty space on the left, but when the user scrolls the list its items are drawn on that (previously empty) space. The top space is always empty. This RecyclerView is inside a FrameLayout with foreground = selectableItemBackground . My problem comes from the fact that the RecyclerView consumes and ignores touches on the left and top spaces, meaning an OnClickListener won

Pan, Zoom and Scale a custom View for Canvas drawing in Android

偶尔善良 提交于 2019-12-23 03:22:40
问题 I'm working on a drawing app, where the user can pan & zoom to a specific portion of the screen and start drawing with zoom applied. To be more specific, I'm looking for a way to implement zoom, pinch & pan gesture in Canvas (horizontal and vertical scrolling with moveable x, y coordinates). Right now, I've successfully developed the zoom only feature but it's not accurate and the pan option is not working. See my sample code here, public class DrawingView extends View { //canvas private