How to customize ItemTouchHelper in RecyclerView Android - java

I have a RecyclerView where I want to enable Swipe to Delete/Star on items. My item is a FrameLayout where a MaterialCardView is on the top and the revealed star and archive layouts are under it.
I already made the swipe behavior work using onTouch method applied on the CardView only, but it's just way too hard to scroll across the list or use onClick or onLongClick as onTouch overrides them. The only way to scroll the RecyclerView or invoke onClick or onLongClick is to move only in Y axis without moving even a half pixel in X, as moving in X will invoke an ACTION_MOVE event that will redirect all next touch events only to the CardView. (requestDisallowInterceptTouchEvent()) as the first statement of the switch case of ACTION_MOVE).
So I want to apply ItemTouchHelper or something similar on the CardView while having the ability to modify the way how the card X changes (To make it slower than user swiping speed like in irremovable notifications in Android) and get the MotionEvent that the user applies, and that's because ItemTouchHelper isn't very literal about what can be treated as a swipe, so it would allow onClick and onLongClick on small movements, and allow scrolling the list when the movement of Y axis is way greater than X's.
Please don't close this question saying "Too board" like a lot of other questions I had a chance to answer :(

Related

Android Studio: ListView OnClick animation doesn't work if you set background color of items

In my project I've setted the background color of my items (composed of several elements inserted in a ConstraintLayout) inside a ListView but the default animation of click and long click disappears if the background color is not at least a little transparent. In fact, as transparency decreases, the effect of clicking on the elements is less and less evident. In a few words, color goes to hide the animation if isn't transparent. How to solve this problem and then bring selection animation to the foreground?
Same problem, still unresolved: ListView items not showing tap animation
RESOLVED!
You have to simply add android:drawSelectorOnTop="true" in your ListView XML tag. In this way you can modify and customize the list item background and at the same time bring back the "selector" on top of the "z axis" of GUI. Yuhu!
If you are giving a background coloraturas to the list items then you might be hiding the system press animations. in this case you can use the methods like OnItemLongClickListener() and itemClickListener () and add your custom animations to the view.

How to make a custom long press menu in recyclerview item

I have a recyclerview, in this recyclerview I have a lot of cardviews with information. I need to make that when the user makes a long press in one of the cards in the recyclerviews. The menu should look like this, with the rounded corners and the icons.
WHAT I HAVE TRIED
I have tried Making a context menu, this didn't worked because the icons and the rounded corners didn't appeared. I have also tried with a popup menu, this didn't work either. The current thing I have, is that I made a layout based on a Recyclerview, changing its position and visibility when a long touch ocurres; this didn't worked as expected, so that's why I am here. I'm trying to make this inside my ViewHolder of my CardAdapter, so I can use the OnLongPressed event.

Android : hide/show footer/header as scrolling scrollview down/up

I am trying to implement a way to have my footer slide away down and my header to slide away up while user scrolls down the scrollview.
And vice-versa, as the user scrolls up the scollview, I want my footer to slide in from the bottom and the header slide in form the top.
Regarding the animation, I have found this good library https://github.com/daimajia/AndroidViewAnimations that comes with a lot of nice animations.
The closest example for what I am looking for, is the default Android Twitter application that makes it's footer disappear as the user scrolls his timeline down and makes it reappear as the user scrolls up.
By header, I am not talking about the Android Toolbar (op AppBar or whatever). It's a customed-made UI element that I want to animate while the user scrolls.
Same thing goes for the footer : it's a customed-made UI element.
While looking for solutions, I stumble upon this answer https://stackoverflow.com/a/28712465/3535408 but it does not work.
Indeed, placing a Log.d inside the ifand else if shows that a simple touch with my finger triggers both a MotionEvent.ACTION_DOWN and a MotionEvent.ACTION_UP event. The same applies as I am sliding my finger up/down making the scrollview scrolls up/down : both events are triggered at the end when I stop touching the scrollview.
Is there a way to improve this solution ? Because as of now, as both MotionEvents are triggered, both animations are also triggered so the result is quite horrible.
Thanks !
An easy way to achieve that would be the following:
place the listview, the header and the footer inside a RelativeLayout
align the header with parent's top
align the footer with parent's bottom
add an empty header and footer to the listview with the same heights
catch the scrolling events on your listview and change the footer and/or header's translationY accordingly
But to answer your question, I'd say you should try a GestureDetector. It's way easier to manage the events - Detecting Gestures

android - slide relativelayout to the side with static buttons

In my Activity I have two RelativeLayouts and two buttons. When you first open the Activity, you have to see a RelativeLayout and the buttons. Then you can slide the RelativeLayout to the right or to the left. The buttons don't move. While sliding, you see the other RelativeLayout below. After a completed slide you see the full RelativeLayout that was below.
How can I implement this in my Android application (min SDK version 14)?
Code examples are a big plus, but not necessary. It is ok to show me the way :)
There's something called a navigation drawer which comes as a template in Android Studio. There are also many sliding menu libraries out there: https://android-arsenal.com/search?q=sliding specifically you might look at https://android-arsenal.com/details/1/1429
If you want to do it from scratch, it'll go something like: have one layout, say a Frame Layout as your root. Then you add the two Relative Layouts and your buttons. Then you need to implement a OnTouchListener in your activity and set on the relative layout that can slide: when the MotionEvent is ACTION_MOVE, you need to calculate the difference between the last touch event and the current touch event and then you can call translateX(dx) on the sliding relative layout where dx is the calculated difference.

Android Horizontal Scrolling that Snaps to List Items

I'd like to implement a UI experience in Android where a user can view a single item (for example, an item in my case is a collection of texts), and swipe left or right on the item to go to the previous or next item.
From my research, ListView does not implement horizontal scrolling. Potential candidates seem to be HorizontalScrollView and GridView, but I haven't seen any examples that can do this simply - only seemingly complicated libraries that need to be included.
My question is, is there a way to use ListView, HorizontalScrollView, GridView, or a combination of them to implement a horizontal scroll that shows one item at a time and snaps to the item being displayed?
The highlighted area in the picture below shows where I'm trying to implement this logic.
It looks like the best option to achieve this experience is a ViewPager, which requires the android support library.
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Categories

Resources