Tha*_*ter 6 android material-design android-coordinatorlayout android-support-design android-appbarlayout
我遇到了新的Android Design Support Librar(http://android-developers.blogspot.com.ar/2015/05/android-design-support-library.html)的一个奇怪问题.如果我在AppBarLayout中放置其他内容(如LinearLayout)以及ToolBar并切换该内容的可见性,那么切换片段将在片段内容的顶部显示死区.
当切换内容的可见性时,AppBarLayout似乎没有正确调整父级CoordinatorLayout的大小.我的CoordinatorLayout包含在DrawerLayout中.我想根据显示的片段切换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>
Run Code Online (Sandbox Code Playgroud)
我在使用支持设计小部件时遇到了类似的问题。我在 DrawerLayout 中有一个 CoordinatorLayout,在 CoordinatorLayout 中有一个 AppBarLayout。我在 AppBarLayout 中有两个工具栏。我的目标是显示一个带有 ViewPager 的工具栏,其中显示 recyclerview 内容。我想在选择项目时在工具栏之间切换。换句话说,我使一个工具栏消失,而另一个工具栏可见,反之亦然。向上滚动内容会将工具栏推离屏幕顶部。一切都很完美,除了改变方向会显示应该消失的工具栏空间。我尝试了所有我能想到的方法来摆脱它,但没有成功。然后我看到这篇文章并意识到这是支持库中的一个错误。然后我尝试将 FrameLayout 放入 AppBarLayout 中,然后将两个工具栏放入 FrameLayout 中,不再有空间!现在一切都按照我的意愿进行。消失的工具栏消失了,即使更改方向,也仅显示可见的工具栏。
希望这对某人有帮助。
| 归档时间: |
|
| 查看次数: |
887 次 |
| 最近记录: |