【发布时间】:2019-03-28 19:16:41
【问题描述】:
我的应用程序包含一个带有工具栏、线性布局和 Tabllayout 的片段。我已启用工具栏的滚动标志。现在,当我尝试在 tablayout 中的 recyclerview 中滚动时,工具栏不会受到阻碍。当我手动推动标签布局时,它开始移动并且能够隐藏或显示。以下是我正在使用的布局。这里有什么问题。
主布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/app">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:background="@color/textcolor"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<Button
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:background="@drawable/backblack" />
</android.support.v7.widget.Toolbar>
<LinearLayout
android:id="@+id/layloc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:orientation="horizontal"
android:weightSum="1"
android:padding="5dp"
android:background="@drawable/border"
android:visibility="gone">
<TextView
android:id="@+id/locationname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableStart="@drawable/location"
android:drawableLeft="@drawable/location"
android:drawablePadding="3dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:textColor="@color/cblack"
android:text="fetching current location"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium.Inverse"/>
<TextView
android:id="@+id/change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Change"
android:drawablePadding="3dp"
android:textColor="@color/cblack"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layloc"
android:background="@color/textcolor"
app:tabTextColor="@color/black"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabIndicatorHeight="2dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
片段布局:
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/textcolor"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/mainexplore">
<android.support.v7.widget.RecyclerView
android:id="@+id/lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/list_divider"
android:dividerHeight="1px"
android:scrollbars="none"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<TextView
android:id="@+id/emptyElement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/nofoodfound"
android:textColor="@color/button"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
我尝试过使用不同的滚动标志,但问题是一样的。我在 SO 中看到了与此类似的示例和一些问题,但没有一个回答我的查询。工具栏可以隐藏但需要手动推送。布局有什么问题。此布局中缺少什么。
【问题讨论】:
-
应用或活动的主题是什么?
-
@KaranMer - 请检查我的布局是否已经存在。
-
我只是用代码完成的。监控滚动变化。然后显示或隐藏它。如果向下滚动,我会隐藏它,如果向上滚动,我会显示它。在滚动更改的代码中非常简单。可能会为自己节省很多时间
标签: android android-fragments android-tablayout android-coordinatorlayout