4

I'm trying to create a custom AbsListView (overriding the same stuff on ListView, GridView and HeaderGridView) that will relocate all its drawing and touching events based on an external factor (other stuff that moves on the layout).

Paddings are not an option here, because then the only way to try to control the AbsListView position is using the super crappy method smoothScrollBy(int distance, int duration) and that is giving me a whole level of different issues that I'm trying to overcome by just all together drawing in a different area of the screen.

At the moment I found out that draw on a different area of the screen is as easy as:

   @Override
   protected void onDraw(Canvas canvas) {
      canvas.translate(0, 400);
      super.onDraw(canvas);
   }

but the touch events don't get translated, and all the touches are 400 pixels up. So I've tried to translate the touch as well with:

   @Override
   public boolean dispatchTouchEvent(MotionEvent ev) {
      ev.offsetLocation(0, -400);
      return super.dispatchTouchEvent(ev);
   }

it does relatively work, to the point that 1) on item click get's called and 2) the view changes color based on the theme android:state_pressed="true", but the Up or Cancel touch evens never get called and the view does not refresh the drawing back to the default color.

I'll still further analyse, but I'm not sure if complex custom adapter with buttons and gesture detector, if that would work or not.

So the question: How can I translate the drawing and still properly get touch events?

Budius
  • 39,391
  • 16
  • 102
  • 144
  • 1
    did you ever find a solution to your problem? I am having similar issues with maintaing the touch positions. – New Guy Jun 30 '15 at 17:29
  • @NewGuy sorry no. Apparently it's not possible. Google just released a design app compat library that seems to do it in a different way – Budius Jun 30 '15 at 17:49
  • thanks for getting back with me. Do you have a reference for it? I have my question posted here too: http://stackoverflow.com/questions/31145595/android-no-touch-events-after-translating-canvas – New Guy Jun 30 '15 at 18:20
  • @NewGuy mainly this class here http://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html – Budius Jul 01 '15 at 07:33

0 Answers0