Android BottomSheetDialog增加了额外的垂直边距

时间:2016-08-10 20:29:43

标签: android android-layout dialog android-dialogfragment bottom-sheet

我有BottomSheetDialogBottomSheetDialogFragment下一个布局:

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorPrimary"
        app:expandedTitleMargin="16dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@color/colorPrimaryDark"
        app:title="Roman R">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="48dp"
            app:layout_collapseMode="parallax"
            app:srcCompat="@drawable/ic_person_white_24dp" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/AppTheme.ToolBarStyle"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <include layout="@layout/profile_info" />

</android.support.v4.widget.NestedScrollView>

两者都会增加额外的上边距,等于Toolbar高度。它看起来像:

enter image description here enter image description here

我的BottomSheetDialogFragment

public class ContactBottomSheet extends BottomSheetDialogFragment {

    @BindView(R.id.collapsing_toolbar)
    public CollapsingToolbarLayout collapsingToolbarLayout;

    private User user;

    @Override
    public void setupDialog(final Dialog dialog, int style) {
        View rootView = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet_contact, null);
        ButterKnife.bind(this, rootView);

        refreshUI();

        dialog.setContentView(rootView);
//        super.setupDialog(dialog, style);
    }

    private void refreshUI() {
        if (getUser() == null) {
            return;
        }

        collapsingToolbarLayout.setTitle(getUser().getName());
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}

我创建了这样的对话框:

 ContactBottomSheet dialog = new ContactBottomSheet();
        dialog.show(getSupportFragmentManager(), "ContactBottomSheet");

请帮助,因为我不知道。

2 个答案:

答案 0 :(得分:1)

正在使用

app:expandedTitleMargin="16dp"

android:padding="48dp"

这会使你的上边距为64dp

<强>解决方案: -

减少并运行

答案 1 :(得分:0)

尝试将其添加到末尾。

var bottomSheet = FindViewById<FrameLayout>(Resource.Id.design_bottom_sheet);
BottomSheetBehavior.From(bottomSheet).State = BottomSheetBehavior.StateExpanded;