gpt4 book ai didi

java - 使用 Android 设计支持库时,工具栏和 ViewPager 之间存在巨大的空白

转载 作者:太空宇宙 更新时间:2023-11-04 13:32:13 25 4
gpt4 key购买 nike

我开始在我的应用程序中使用 Android 设计支持库。我开始使用带有 AppBarLayout 的 CoordinatorLayout 和带有 ViewPager 的工具栏来创建工具栏在滚动时离开屏幕的动画。

到目前为止,效果很好。问题所在是每当方向从纵向更改为横向,然后从横向更改为纵向时。其结果是工具栏和 ViewPager 之间出现较大的空白区域。有谁知道如何解决这一问题?谢谢!代码如下,我会添加问题的屏幕截图,但显然直到我达到 10 级或其他级别时我才能这样做。

这是布局文件 (activity_main.xml):

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<!--Content Container-->
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<!--App Bar Container-->
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<!--ActionBar-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"/>

<!--Prevents a bug in the App Bar Layout-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1px"/>

<!--Tabs-->
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:tabMode="scrollable"
app:tabGravity="fill"
app:tabIndicatorHeight="@dimen/toolbar_tab_indicator_height"
app:tabTextColor="@color/colorPrimaryLight"
app:tabSelectedTextColor="@color/textColor"/>
</android.support.design.widget.AppBarLayout>

<!--Body Content-->
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>


<!--Navigation Drawer-->
<android.support.design.widget.NavigationView
android:id="@+id/navigationView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_items"/>
</android.support.v4.widget.DrawerLayout>

最佳答案

我相信内容持有者,即您的 ViewPager,属于 CoordinatorLayout 内部。我在 CoordinatorLayout 之外看到的唯一东西是导航 View 或抽屉。

关于java - 使用 Android 设计支持库时,工具栏和 ViewPager 之间存在巨大的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32058594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com