【问题标题】:RecyclerView Not Scrolling in NavigationViewRecyclerView 在 NavigationView 中不滚动
【发布时间】:2018-05-04 16:20:39
【问题描述】:

我在从右侧滑入的抽屉布局导航视图中有两个回收器视图。在顶部水平滚动的那个可以工作,尽管您必须先按住其他地方,这样它就不会认为您正在尝试将视图滑回。但是,更大的问题是消息的第二个回收器视图不允许您滚动。我尝试删除所有额外的属性,如可点击和转录模式,并尝试将该回收器视图移动到 XML 的底部,但均未奏效。这是我的主页 XML:

<?xml version="1.0" encoding="utf-8"?>
<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">

    <RelativeLayout
        android:id="@+id/activity_user_marker_details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.test.test.User_Marker_Details"
        android:layout_centerVertical="false"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/userMarkerToolbar"
            style="@style/HeaderBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#279d43"
            android:elevation="4dp"
            android:minHeight="?attr/actionBarSize"
            android:transitionName="actionBar"
            app:popupTheme="@style/ActionBarPopupThemeOverlay"
            app:theme="@style/ActionBarThemeOverlay"
            app:title="Go Back"
            app:titleTextColor="@color/md_white_1000"
            tools:ignore="UnusedAttribute" />

        <RelativeLayout
            android:id="@+id/topRL"
            android:layout_below="@id/userMarkerToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:text="00"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:id="@+id/textViewUserMarkerDetCount"
                android:textSize="60sp"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp"
                tools:ignore="HardcodedText" />

            <LinearLayout
                android:id="@+id/peopleInHerdLinearLayout"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/textViewUserMarkerDetCount"
                android:layout_toEndOf="@+id/textViewUserMarkerDetCount"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp">

                <TextView
                    android:text="people"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView2"
                    android:textSize="24sp"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:text="in the herd"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView4"
                    android:textSize="18sp"
                    tools:ignore="HardcodedText" />

            </LinearLayout>

            <TextView
                android:layout_toRightOf="@id/peopleInHerdLinearLayout"
                android:text="Outdoor Activity"
                android:lines="1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAlignment="viewEnd"
                android:id="@+id/categoryTextView"
                android:layout_marginTop="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginEnd="5dp"
                android:gravity="end"
                android:layout_toEndOf="@id/peopleInHerdLinearLayout"
                tools:ignore="HardcodedText" />

            <ImageView
                android:id="@+id/notifyHerdButtonBackground"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_below="@id/categoryTextView"
                android:layout_alignParentRight="true"
                android:layout_margin="5dp"
                android:background="@drawable/circle_background_green"
                android:layout_alignParentEnd="true"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/notifyHerdButton"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/cow"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:layout_alignTop="@id/notifyHerdButtonBackground"
                android:layout_alignLeft="@id/notifyHerdButtonBackground"
                android:layout_alignStart="@id/notifyHerdButtonBackground"
                android:layout_marginStart="10dp" />

        </RelativeLayout>

        <TextView
            android:layout_below="@id/topRL"
            android:text="people who joined the herd..."
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView7"
            android:textAlignment="center"
            android:textStyle="normal|italic"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            tools:ignore="HardcodedText" />

        <ListView
            android:layout_below="@id/textView7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/myUserCheckedInListView" />

        <ImageButton
            android:id="@+id/herdchatButton"
            android:layout_width="40dp"
            android:layout_height="50dp"
            android:background="@drawable/herdchat_button"
            android:paddingTop="5dp"
            android:src="@drawable/ic_action_chat"
            android:scaleType="fitCenter"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_below="@id/topRL"
            android:layout_marginTop="50dp"
            android:paddingRight="5dp"
            android:paddingLeft="10dp"
            android:paddingStart="10dp"
            android:paddingEnd="5dp"
            tools:ignore="ContentDescription" />

    </RelativeLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/herdchatSlideInView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="0dp"
        android:layout_gravity="end"
        android:fitsSystemWindows="true"
        android:layout_marginStart="0dp">

        <include layout="@layout/activity_herdchat"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

上面包含的XML,有recyclerview:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_user__subscriptions"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.test.test.HerdchatActivity"
    android:background="@color/white"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:id="@+id/herdchatHerdsRecyclerView"
        android:orientation="horizontal"
        tools:listitem="@layout/herdchat_herds"/>

    <View
        android:id="@+id/separatorView"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/logoGreen"
        android:layout_below="@id/herdchatHerdsRecyclerView"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/messagesRecylcerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/separatorView"
        android:transcriptMode="alwaysScroll"
        android:layout_above="@+id/divider"
        android:divider="@null"
        android:clickable="false"
        android:dividerHeight="0dp"
        android:stackFromBottom="true"
        tools:listitem="@layout/chat_message_left"/>

    <RelativeLayout
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/logoGreen"
        android:layout_above="@+id/relSendMessage" />

    <RelativeLayout
        android:id="@+id/relSendMessage"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:background="@color/white"
        android:paddingLeft="10dp"
        android:paddingStart="10dp"
        android:paddingRight="0dp"
        android:paddingEnd="0dp"
        android:layout_alignParentBottom="true">


        <EditText
            android:layout_marginBottom="-4dp"
            android:id="@+id/messageBodyField"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="14sp"
            android:textColor="@color/logoGreen"
            android:layout_marginRight="10dp"
            android:layout_marginEnd="10dp"
            android:layout_alignTop="@+id/btnSend"
            android:background="@color/white"
            android:layout_alignBottom="@+id/btnSend"
            android:layout_toLeftOf="@+id/btnSend"
            android:layout_toStartOf="@+id/btnSend"
            android:inputType="text"
            tools:ignore="LabelFor" />

        <Button
            android:id="@+id/btnSend"
            android:layout_width="72dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_margin="4dp"
            android:fontFamily="sans-serif-condensed"
            android:textStyle="bold"
            android:textSize="16sp"
            android:text="Send"
            android:textColor="@color/white"
            android:background="@color/logoGreen"
            tools:ignore="HardcodedText" />

    </RelativeLayout>
</RelativeLayout>

更改为下面允许它滚动,但现在当以任何速度向上滚动时,除了非常慢之外,如果有人知道解决此问题的方法,例如禁用滑入,则导航视图会关闭。感动?:

<android.support.v4.widget.NestedScrollView
        android:layout_marginTop="30dp"
        android:id="@+id/herdchatHerdsNestedSV"
        android:layout_width="match_parent"
        android:layout_height="75dp">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/herdchatHerdsRecyclerView"
            android:nestedScrollingEnabled="true"
            android:orientation="horizontal"
            tools:listitem="@layout/herdchat_herds"
            tools:ignore="UnusedAttribute" />
    </android.support.v4.widget.NestedScrollView>

    <View
        android:id="@+id/separatorView"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/logoGreen"
        android:layout_below="@id/herdchatHerdsNestedSV"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"/>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/messagesNestedSV"
        android:layout_width="match_parent"
        android:layout_below="@id/separatorView"
        android:layout_above="@+id/divider"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/messagesRecylcerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:transcriptMode="alwaysScroll"
            android:nestedScrollingEnabled="true"
            android:divider="@null"
            android:clickable="false"
            android:dividerHeight="0dp"
            android:stackFromBottom="true"
            tools:listitem="@layout/chat_message_left"
            tools:ignore="UnusedAttribute" />
    </android.support.v4.widget.NestedScrollView>

此外,alwaysScroll 不再工作了,所以我正在尝试这个,这是半工作的,我认为我只需要多玩一些,除非有人知道更好的方法:

    mMessagesNestedSV.fullScroll(View.FOCUS_DOWN);

【问题讨论】:

  • 也尝试放置嵌套滚动
  • 您是否尝试过启用回收站视图的嵌套滚动属性?
  • 如果你不使用NavigationView 来实现它的特定功能——即内置菜单、标题支持等——那么就去掉它。 RelativeLayout 本身可以充当抽屉。它不一定是NavigationView。只要确保适当的layout_gravity 属性是您用作抽屉的任何东西。此外,NavigationView 并不是真的要添加任意的Views。它具有特定的功能,并构建了自己的内部结构。
  • 非常有帮助,谢谢!

标签: android xml android-recyclerview


【解决方案1】:

这应该对你有用,以便在单个视图中拥有更多数量的滚动条,你必须将嵌套滚动条作为根元素或至少作为所有滚动条的父级。

    <?xml version="1.0" encoding="utf-8"?>
<NestedScrollView     xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
>
    <RelativeLayout 
        android:id="@+id/activity_user__subscriptions"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.test.test.HerdchatActivity"
        android:background="@color/white"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="75dp"
            android:id="@+id/herdchatHerdsRecyclerView"
            android:orientation="horizontal"
            tools:listitem="@layout/herdchat_herds"/>

        <View
            android:id="@+id/separatorView"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/logoGreen"
            android:layout_below="@id/herdchatHerdsRecyclerView"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="0dp"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/messagesRecylcerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/separatorView"
            android:transcriptMode="alwaysScroll"
            android:layout_above="@+id/divider"
            android:divider="@null"
            android:clickable="false"
            android:dividerHeight="0dp"
            android:stackFromBottom="true"
            tools:listitem="@layout/chat_message_left"/>

        <RelativeLayout
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/logoGreen"
            android:layout_above="@+id/relSendMessage" />

        <RelativeLayout
            android:id="@+id/relSendMessage"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:background="@color/white"
            android:paddingLeft="10dp"
            android:paddingStart="10dp"
            android:paddingRight="0dp"
            android:paddingEnd="0dp"
            android:layout_alignParentBottom="true">


            <EditText
                android:layout_marginBottom="-4dp"
                android:id="@+id/messageBodyField"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textSize="14sp"
                android:textColor="@color/logoGreen"
                android:layout_marginRight="10dp"
                android:layout_marginEnd="10dp"
                android:layout_alignTop="@+id/btnSend"
                android:background="@color/white"
                android:layout_alignBottom="@+id/btnSend"
                android:layout_toLeftOf="@+id/btnSend"
                android:layout_toStartOf="@+id/btnSend"
                android:inputType="text"
                tools:ignore="LabelFor" />

            <Button
                android:id="@+id/btnSend"
                android:layout_width="72dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_margin="4dp"
                android:fontFamily="sans-serif-condensed"
                android:textStyle="bold"
                android:textSize="16sp"
                android:text="Send"
                android:textColor="@color/white"
                android:background="@color/logoGreen"
                tools:ignore="HardcodedText" />

        </RelativeLayout>
    </RelativeLayout>

</NestedScrollView?

【讨论】:

  • 我必须更改的格式,请参阅我的更新,但 nestedscroll 确实有帮助,谢谢!
猜你喜欢
  • 2021-02-15
  • 1970-01-01
  • 2020-07-09
  • 2018-08-04
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
相关资源
最近更新 更多