Title: Removing the extra space from Top of BottomSheet
Tags: android;android-layout
Question: I added bottomsheet in my application.ii work good but only problem is extra space it cover and I just want to remove those extra spaces on the top of Bottomsheet layout.

I want to remove the highlighted part:



How I can remove those extra spaces?

Here is my XML

```<?xml version="1.0" encoding="utf-8"?&gt;
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:id="@+id/coordinatorLayout"
    tools:context=".MainActivity"&gt;

    <include layout="@layout/content_main" /&gt;

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:orientation="horizontal"
        app:behavior_hideable="true"
        app:behavior_peekHeight="0dp"
        android:id="@+id/bottom_sheet"
        android:background="@android:color/white"
        app:layout_behavior="@string/bottom_sheet_behavior"&gt;

            <ImageView
                android:layout_weight="1"
                android:layout_margin="@dimen/five"
                android:padding="@dimen/ten"
                android:src="@drawable/ic_photo_camera"
                android:layout_width="@dimen/fifty"
                android:layout_height="@dimen/fifty" /&gt;

            <ImageView
                android:layout_weight="1"
                android:layout_margin="@dimen/five"
                android:padding="@dimen/ten"
                android:src="@drawable/ic_image_gallery"
                android:layout_width="@dimen/fifty"
                android:layout_height="@dimen/fifty" /&gt;

            <ImageView
                android:layout_weight="1"
                android:layout_margin="@dimen/five"
                android:padding="@dimen/ten"
                android:src="@drawable/ic_video_camera"
                android:layout_width="@dimen/fifty"
                android:layout_height="@dimen/fifty" /&gt;

            <ImageView
                android:layout_weight="1"
                android:layout_margin="@dimen/five"
                android:padding="@dimen/ten"
                android:src="@drawable/ic_video"
                android:layout_width="@dimen/fifty"
                android:layout_height="@dimen/fifty" /&gt;


    </LinearLayout&gt;

</android.support.design.widget.CoordinatorLayout&gt;
```

Here is my Java code

```public class MainActivity extends AppCompatActivity {


    BottomSheetBehavior behavior;
    View bottomSheet;
    CoordinatorLayout coordinatorLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);

        bottomSheet = findViewById(R.id.bottom_sheet);
        behavior = BottomSheetBehavior.from(bottomSheet);
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                // React to state change
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                // React to dragging events
            }
        });


        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        });
    }

//        Snackbar.make(coordinatorLayout,item + " is selected", Snackbar.LENGTH_LONG).setAction("Action", null).show();
//        behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            if (behavior.getState()==BottomSheetBehavior.STATE_EXPANDED) {

                Rect outRect = new Rect();
                bottomSheet.getGlobalVisibleRect(outRect);

                if(!outRect.contains((int)ev.getRawX(), (int)ev.getRawY()))
                    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            }
        }
        return super.dispatchTouchEvent(ev);
    }
}
```

Comment: Remove the top margin/padding from your BottomSheet or give it a negative value.


Here is another answer: I think I have got the answer. Just need to remove the ```android:fitsSystemWindows="true"``` from bottom_sheet i.e the LinearLayout.
Just in case I am putting the xml code below.

```<?xml version="1.0" encoding="utf-8"?&gt;
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:id="@+id/coordinatorLayout"
    tools:context=".MainActivity"&gt;

    <include layout="@layout/content_main" /&gt;


    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="horizontal"
        app:behavior_hideable="true"
        app:behavior_peekHeight="0dp"
        android:id="@+id/bottom_sheet"
        android:background="@android:color/holo_orange_light"
        app:layout_behavior="@string/bottom_sheet_behavior" 
        xmlns:android="http://schemas.android.com/apk/res/android"&gt;

        <ImageView
            android:layout_weight="1"
            android:layout_margin="@dimen/five"
            android:padding="@dimen/ten"
            android:src="@drawable/ic_photo_camera"
            android:layout_width="@dimen/fifty"
            android:layout_height="@dimen/fifty" /&gt;

        <ImageView
            android:layout_weight="1"
            android:layout_margin="@dimen/five"
            android:padding="@dimen/ten"
            android:src="@drawable/ic_image_gallery"
            android:layout_width="@dimen/fifty"
            android:layout_height="@dimen/fifty" /&gt;

        <ImageView
            android:layout_weight="1"
            android:layout_margin="@dimen/five"
            android:padding="@dimen/ten"
            android:src="@drawable/ic_video_camera"
            android:layout_width="@dimen/fifty"
            android:layout_height="@dimen/fifty" /&gt;

        <ImageView
            android:layout_weight="1"
            android:layout_margin="@dimen/five"
            android:padding="@dimen/ten"
            android:src="@drawable/ic_video_camera"
            android:layout_width="@dimen/fifty"
            android:layout_height="@dimen/fifty" /&gt;


    </LinearLayout&gt;
</android.support.design.widget.CoordinatorLayout&gt;
```

Just for my use, I have used different drawable you need to change it back to the original one.

Hope it helps!


Here is another answer: ```    android:fitsSystemWindows=&quot;false&quot;
```
Will work!


Here is another answer: I had the same problem. What worked for me was moving ```android:layout-behaviour``` from the ```LinearLayout``` to the ```coordinatorLayout```. Or just removing it all together.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:06/09/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-layout>', 'Title': 'Removing the extra space from Top of BottomSheet', 'ViewCount': 2424, 'id': 50772642, 'user_AboutMe': '', 'user_AccountId': 4739482.0, 'user_DisplayName': 'Pritesh Vishwakarma', 'user_Reputation': 328.0, 'user_Views': 154.0, 'user_id': 3832773.0}}