有许多很好的教程使用NestedScrollView
讨论BottomSheet。但是在我使用我目前的支持库版本24.2.1进行尝试后,我花了几天时间,并不知道为什么我的包含顶部填充。
这是我的Activity的布局xml:
<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"
tools:context=".ui.MainActivity">
<!-- AppBar -->
<include
android:id="@+id/appBar"
layout="@layout/app_bar_layout_with_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabPager="@{tabPager}" />
<!-- Content -->
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<!-- [START] BottomSheet -->
<include
android:id="@+id/bottomSheetMain"
layout="@layout/fragment_bottom_sheet_song"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:behavior_hideable="false"
app:behavior_peekHeight="0dp"
app:layout_behavior="@string/bottom_sheet_behavior" />
<!-- [END BottomSheet] -->
</android.support.design.widget.CoordinatorLayout>
而BottomSheet的布局fragment_bottom_sheet_song.xml
:
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgBottomSheetPlayer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/bottomSheetPlayer"
layout="@layout/view_bottom_sheet_player_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:playAction="@{playAction}"
app:playObject="@{playSong}" />
<include
android:id="@+id/bottomSheetContent"
layout="@layout/view_action_detail_song"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:playSong="@{playSong}"
app:songActionHandler="@{songActionHandler}" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
为什么有顶部填充?我怎样才能解决这个问题?
谢谢。
经过几天的努力,我发现要解决这个问题,持久的底部布局容器必须是FrameLayout
。如果不是(就像我的情况,我直接包括NestedScrollView
并使它成为底页),它将包含默认的顶部填充,我仍然不知道为什么。
所以这是我要修复的新Activity的xml布局代码:
<!-- [START] BottomSheet -->
<FrameLayout
android:id="@+id/bottomSheetParent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:behavior_hideable="false"
app:behavior_peekHeight="0dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<include
android:id="@+id/bottomSheetMain"
layout="@layout/fragment_bottom_sheet_song"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<!-- [END BottomSheet] -->
希望这也对你有所帮助。
我认为您需要从此视图的根布局android:fitsSystemWindows="true"
中删除标记android.support.design.widget.CoordinatorLayout
。您的源代码布局将是这样的。
<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"
tools:context=".ui.MainActivity">
<!-- children contents -->
</android.support.design.widget.CoordinatorLayout>
希望这有帮助。
尝试在Activity清单中添加它,显然在我的情况下,键盘会导致底部表格自动填充。
android:windowSoftInputMode="adjustPan"