使用 SearchView 后底部出现意外边距 sheet

Unexpected margin in bottom sheet after using SearchView

我在使用 SearchViewBottomSheet 时遇到了一个奇怪的问题。

BottomSheet 在使用 SearchView 之后使用时会得到意外的余量。他们的视频解释了这个问题。

Video

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout    
<xmlns:android="http://schemas.android.com/apk/res/android"   
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundcolor"
android:fitsSystemWindows="true">


<android.support.v7.widget.RecyclerView
    android:id="@+id/trip_recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundcolor"
    android:clipToPadding="false"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="32dp"
        android:orientation="vertical"
        android:padding="12dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:text="Sort &amp; Filter"
                android:textColor="@color/black"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/sheet_done"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:drawablePadding="8dp"
                android:drawableStart="@drawable/ic_done"
                android:text="Done"
                android:textSize="18sp" />

        </RelativeLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="Sort By" />

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <Spinner
                    android:id="@+id/sheet_spinner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:entries="@array/sort_by"
                    android:padding="8dp" />
            </LinearLayout>

        </android.support.v7.widget.CardView>


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="Price Range" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="12dp"
            android:layout_marginTop="8dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/sheet_price_min"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/sheet_price_max"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:gravity="end" />


        </LinearLayout>

        <SeekBar
            android:id="@+id/sheet_bar_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:thumb="?android:attr/textSelectHandle" />

        <TextView
            android:id="@+id/sheet_price_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Rs 1,115" />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="Ratings" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="12dp"
            android:layout_marginTop="8dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="1" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="12dp"
                android:layout_weight="1"
                android:gravity="start"
                android:text="2" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="3" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="12dp"
                android:layout_weight="1"
                android:gravity="end"
                android:text="4" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="end"
                android:text="5" />


        </LinearLayout>

        <SeekBar
            android:id="@+id/sheet_bar_rating"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="4"
            android:thumb="?android:attr/textSelectHandle" />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="Packages" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <CheckBox
                android:id="@+id/sheet_package_gold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:layout_weight="1"
                android:text="Gold" />

            <CheckBox
                android:id="@+id/sheet_package_diamond"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:layout_weight="1"
                android:text="Diamond" />


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <CheckBox
                android:id="@+id/sheet_package_silver"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:layout_weight="1"
                android:text="Silver" />

            <CheckBox
                android:id="@+id/sheet_package_platinum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:layout_weight="1"
                android:text="Platinum" />

        </LinearLayout>
    </LinearLayout>
 </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Activity

public class TripsActivity extends AppCompatActivity implements
    SearchView.OnQueryTextListener, SeekBar.OnSeekBarChangeListener, View.OnClickListener {

public String MAX = "150000";
public String MIN = "0";
@BindView(R.id.trip_recyclerView)
RecyclerView recyclerView;
@BindView(R.id.bottom_sheet)
View view;
@BindView(R.id.sheet_spinner)
Spinner spinner;
@BindView(R.id.sheet_price_min)
TextView minPrice;
@BindView(R.id.sheet_price_max)
TextView maxPrice;
@BindView(R.id.sheet_price_text)
TextView currentPrice;
@BindView(R.id.sheet_bar_price)
SeekBar priceBar;
@BindView(R.id.sheet_bar_rating)
SeekBar ratingBar;
@BindView(R.id.sheet_package_gold)
CheckBox packageGold;
@BindView(R.id.sheet_package_silver)
CheckBox packageSilver;
@BindView(R.id.sheet_package_platinum)
CheckBox packagePlatinum;
@BindView(R.id.sheet_package_diamond)
CheckBox packageDiamond;

BottomSheetBehavior.BottomSheetCallback callback = new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(@NonNull View bottomSheet, int newState) {
    }

    @Override
    public void onSlide(@NonNull View bottomSheet, float slideOffset) {

        if (slideOffset < 0.4)
            getSupportActionBar().show();
        else
            getSupportActionBar().hide();

    }

};
private SearchView searchView;
private TripsAdapter adapter;
private BottomSheetBehavior mBottomSheetBehavior;

@OnClick(R.id.sheet_done)
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.sheet_done:
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            break;
    }
}


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_trips_activity);
    ButterKnife.bind(this);


    mBottomSheetBehavior = BottomSheetBehavior.from(view);
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    mBottomSheetBehavior.setPeekHeight(0);
    mBottomSheetBehavior.setBottomSheetCallback(callback);
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        else
            this.finish();

    } else if (item.getItemId() == R.id.filterOptions)
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.seach_meanu, menu);

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    searchView.setOnQueryTextListener(this);

    return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
    adapter.filter(query);
    return true;
}

@Override
public boolean onQueryTextChange(String newText) {
    adapter.filter(newText);
    return true;
}

@Override
public void onBackPressed() {
    if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    else
        super.onBackPressed();
}


}

有人可以帮我找出问题所在。谢谢

将此添加到您的 manifest.This 由 softkeyboard.Sadly 触发的问题我找不到问题的真正根源。

<activity>
   android:name=..
   android:windowSoftInputMode="adjustPan">

我从 :