【问题标题】:Scrolling recyclerview in fragment causes view to be pushed up在片段中滚动 recyclerview 会导致视图被向上推
【发布时间】:2017-03-31 04:40:07
【问题描述】:

当我尝试在我的 recyclerview 片段中滚动时,整个视图都被向上推了。

片段代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />

</RelativeLayout>

列表布局代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="true"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:clickable="true"
    android:orientation="vertical">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:text="Title"
        android:textColor="#000000"
        android:textSize="16dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/location"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Location"
        android:layout_below="@+id/title"
        android:layout_alignParentStart="true" />

    <TextView
        android:id="@+id/date"
        android:textColor="#000000"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:text="Date"
        />
</RelativeLayout>

工具栏代码

 <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

我尝试将片段更改为 wrap_content 而不是 match_parent,当我尝试在内容区域滚动时,同样的问题会出现在视图被向上推的位置

【问题讨论】:

  • 你有工具栏吗?你能发布你的工具栏代码吗?
  • 添加了工具栏代码
  • 尝试将match_parent 赋予第一个RelativeLayout 高度

标签: android android-layout android-fragments


【解决方案1】:

您的工具栏滚动标志需要如下更改,

 app:layout_scrollFlags="scroll|exitUntilCollapsed"

除了 exitUntilCollapsed,您还可以尝试其他一些属性

1)enterAlways 2)enterAlwaysCollapsed

并且您的 recyclerview 父级 RelativeLayout 应该具有以下属性。

app:layout_behavior="@string/appbar_scrolling_view_behavior"

【讨论】:

  • 感谢您解决了问题。当我滚动时,我怎么能这样做,应用栏隐藏而不是 Tablayout
  • 找不到你。请详细说明您的问题。如果解决方案有帮助,请接受并投票。
  • 我希望现在显示“Quido”的 AppBar 在滚动时隐藏,只留下 TabBar 可见
  • 所以,当你滚动 Quido 时应该隐藏。不是吗?
  • 目前没有隐藏
猜你喜欢
  • 1970-01-01
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-03
相关资源
最近更新 更多