I am making an android app. In which I have a scenario. First watch screen shot below so any one come here to answer has some clear picture that what I want.
Material way
You can archive it(or, at least, very close to what you want) with CoordinatorLayout and keeping your map layout inside CollapsingToolbarLayout
.
Your layout can look like this:
.....
You can read more here Android Design Support Library and here Design Support Library (III): Coordinator Layout
View.OnTouchListener
way
(This is the one you use)
Idea is simple:
android:layout_above
red separator & ListView - android:layout_below
red separatorHere's how it looks:
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
private int _yDelta;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
findViewById(R.id.separator).setOnTouchListener(this);
}
@Override
public boolean onTouch(View view, MotionEvent event) {
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_yDelta = Y - lParams.bottomMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
layoutParams.bottomMargin = (Y - _yDelta);
layoutParams.topMargin = -layoutParams.bottomMargin;
view.setLayoutParams(layoutParams);
view.animate().translationY(Y - _yDelta).setDuration(0);
break;
}
findViewById(R.id.root).invalidate();
return true;
}
}
And activity_main.xml
:
I hope, it helps!