gpt4 book ai didi

android - 切换可见性 AppBarLayout View 会导致加载 fragment 的间距问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:45 25 4
gpt4 key购买 nike


我在使用新的 Android 设计支持库 (http://android-developers.blogspot.com.ar/2015/05/android-design-support-library.html) 时遇到了一个奇怪的问题。如果我将其他内容(如 LinearLayout)与 ToolBar 一起放置在 AppBarLayout 中并切换该内容的可见性,则切换 fragment 将在 fragment 内容的顶部显示死区。

当切换内容的可见性时,AppBarLayout 似乎没有正确调整父 CoordinatorLayout 的大小。我将我的 CoordinatorLayout 包裹在 DrawerLayout 中。我想根据显示的 fragment 切换 AppBarLayout 中额外 LinearLayout 的可见性。

这是我的 MainActivity 的 main.xml 文件:

<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.CoordinatorLayout
android:layout_height="match_parent"
android:layout_width="match_parent">

<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>

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

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:text="Hello"/>
</LinearLayout>

</android.support.design.widget.AppBarLayout>

<FrameLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer"/>

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

最佳答案

我在使用支持设计小部件时遇到了类似的问题。我在 DrawerLayout 中有一个 CoordinatorLayout,在 CoordinatorLayout 中有一个 AppBarLayout。我在 AppBarLayout 中有两个工具栏。我的目标是显示一个带有显示回收 View 内容的 ViewPager 的工具栏。我想在选择项目时在工具栏之间切换。换句话说,我让一个工具栏消失了,而另一个工具栏可见,反之亦然。向上滚动内容会将工具栏向上推离屏幕顶部。除了改变方向会显示应该消失的工具栏空间外,一切都运行良好。我尝试了所有我能想到的方法来摆脱它,但没有成功。然后我看到了这篇文章,意识到这是支持库中的一个错误。然后我尝试将一个 FrameLayout 放在 AppBarLayout 中,然后将两个工具栏放在 FrameLayout 中并且没有更多空间!现在一切都按照我的预期进行。 GONE 工具栏已消失,仅显示可见的工具栏,即使在更改方向时也是如此。

希望这对某人有帮助。

关于android - 切换可见性 AppBarLayout View 会导致加载 fragment 的间距问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31078265/

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