0

I want to make detail view. When clicking on an object, a detail layout appears from the bottom. It is possible to move the layout by touching any where on the layout.

I've used some code, it doesn't work correct. When I touch the layout, top side of the layout appears on the bottom of touching point. Plus there is some margin between touching point and top side of layout

Example pics shows what I mean. It is mapping app "2gis"

mLinearLayout.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent event) {

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
        if (view.getId() != R.id.bottomPanel) return false;

        switch (event.getAction())
        {
            case MotionEvent.ACTION_MOVE:
                params.topMargin = (int)event.getRawY();
                view.setLayoutParams(params);
                break;

            case MotionEvent.ACTION_UP:

                view.setLayoutParams(params);
                break;

            case MotionEvent.ACTION_DOWN:
                break;
        }

        return true;
    }
});

example 1

example 2

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39

2 Answers2

2

What you're looking for is called a Bottom sheet in material design. It's included in the Android design support library v23.2.+.

All you need to do is to set the layout_behavior of the container view to BottomSheetBehavior:

app:layout_behavior="android.support.design.widget.BottomSheetBehavior"

Here are some nice tutorials on how to implement Bottom sheet in Android :

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39
  • thanks for your answer. Does it work on old versions? android 4.4 for example? – Чечил Крым Jul 20 '16 at 12:41
  • yes it does work on older versions, that's what support libraries do, read this for more details on what the support library does :http://stackoverflow.com/questions/12926548/what-is-an-android-support-library – Ashish Ranjan Jul 20 '16 at 12:44
  • you're welcome @ЧечилКрым, you can mark the answer as correct so that others can benefit from the answer. – Ashish Ranjan Jul 20 '16 at 14:19
0

It's android feature bottom sheet.

You can use bottom sheet this design library.

compile 'com.android.support:design:23.2.0'

Here some tutorial which help you for development.

http://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031

https://github.com/Flipboard/bottomsheet

ViramP
  • 1,659
  • 11
  • 11