我在一个从右侧滑入的drawerlayout导航视图中有两个recyclerviews。在顶部水平滚动的那个可以工作,虽然你必须先把它放在别处,所以事情并不认为你试图将视图滑回来。但更大的问题是,消息的第二个回收站视图不允许您滚动。我尝试删除所有额外的属性,如clickable和transcriptmode,并尝试将该回收站视图移动到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);
答案 0 :(得分: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?