How to set layout params using view's on touch listener?

540 Views Asked by At

Expected Result or Actual Screen

I want to create drawing layout like this xml layout of screen

Layout at the bottom in gray is like a drawer its can be adjusted by dragging up and down. So I want to adjust its hight when user takes it up or down. I have used onTouchListener for this but I am not getting the expected result. My touchlistner is as onTouchListener

I have also referred git lib source, need help or any suggestion to implement the bottom drawer as shown in screen.

1

There are 1 best solutions below

0
On

check smth like this:

setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        ((LayoutParams)slidingLayout.getLayoutParams()).marginTop=event.getY();
        return true;
    }
}

listener for whole parent view

edit: oh, my reading skills are really poor, I'm assuming you want to get out this view by touching blue small view...

so for the first you have to calculate position of touch in this view (ACTION_DOWN) - how much above bottom - and this will be your start point, so-called "0". then when ACTION_MOVE use event.getY() and previously calculated start point for setting marginTop (or setY() if API allows). for ACTION_UP you might recognize if whole layout is dragged out and if not you might set marginTop fixed value wholeViewHeight - draggedViewDesiredHeight