Recycleview不在嵌套的scrollview android中滚动

时间:2016-10-01 10:10:02

标签: android android-scrollview

<?xml version="1.0" encoding="utf-8"?>
<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/todoDetailsCoordinatorLayout"
    android:background="@color/windowBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/todoEditMainLl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/windowBackground"
        android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/todoDetailsAppBar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/toolbar_height"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/todoDetailsToolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:contentInsetStart="10dp"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.AppBarLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/todoDetailsBottomLl"
            android:layout_below="@+id/todoDetailsAppBar"
            android:orientation="vertical">

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/todoDetailsScrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent">


                <LinearLayout
                    android:id="@+id/todoEditTopLl"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/windowBackground"
                    android:orientation="vertical"
                    android:visibility="visible">

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingTop="@dimen/eight_dp">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical"
                            android:paddingLeft="@dimen/activity_vertical_margin"
                            android:paddingRight="@dimen/activity_vertical_margin">


                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/list_item_single_line_height"
                                android:gravity="center_vertical"
                                android:orientation="horizontal">

                                <LinearLayout
                                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                                    android:gravity="center"
                                    android:orientation="vertical">

                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:src="@drawable/todo_user"
                                        android:visibility="visible" />
                                </LinearLayout>

                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_marginLeft="@dimen/list_item_content_left_padding"
                                    android:gravity="center_vertical"
                                    android:orientation="vertical">

                                    <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                        android:id="@+id/EditTodoTxtAssignToName"
                                        android:layout_width="match_parent"
                                        android:layout_height="wrap_content"
                                        android:singleLine="true"
                                        android:text="" />

                                    <com.strait.solvenow.Utilities.WithoutSecondaryTextView
                                        android:id="@+id/EditTodoTxtAssignByName"
                                        android:layout_width="match_parent"
                                        android:layout_height="wrap_content"
                                        android:singleLine="true"
                                        android:text=""

                                        />
                                </LinearLayout>
                            </RelativeLayout>

                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/todo_details_height"
                                android:gravity="center"
                                android:orientation="horizontal">

                                <LinearLayout
                                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                                    android:gravity="center"
                                    android:orientation="vertical">

                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:gravity="center_vertical"
                                        android:src="@drawable/todo_due_date" />
                                </LinearLayout>

                                <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                    android:id="@+id/EditToDoTxtDueDate"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_marginLeft="@dimen/list_item_content_left_padding"
                                    android:background="@null"
                                    android:gravity="left|center"
                                    android:text="@string/Due_Date" />

                            </RelativeLayout>

                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/todo_details_height"
                                android:gravity="center_vertical"
                                android:orientation="horizontal">

                                <LinearLayout
                                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                                    android:gravity="center"
                                    android:orientation="vertical">

                                    <ImageView
                                        android:id="@+id/todoDetailsImgStatus"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:src="@drawable/user_place_holder" />
                                </LinearLayout>

                                <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                    android:id="@+id/EditToDoTxtStatus"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_marginLeft="@dimen/list_item_content_left_padding"
                                    android:background="@null"
                                    android:gravity="left|center"
                                    android:text="@string/Status" />

                            </RelativeLayout>

                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/todo_details_height"
                                android:gravity="center|left"
                                android:orientation="horizontal">

                                <LinearLayout
                                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                                    android:gravity="center"
                                    android:orientation="vertical">

                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:src="@drawable/todo_notification" />
                                </LinearLayout>

                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_marginLeft="@dimen/list_item_content_left_padding"
                                    android:orientation="horizontal">

                                    <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                        android:id="@+id/todoDetailsTxtNotify"
                                        android:layout_width="wrap_content"
                                        android:layout_height="match_parent"
                                        android:gravity="center"
                                        android:text="@string/Notifications" />


                                    <android.support.v7.widget.SwitchCompat
                                        android:id="@+id/todoEditTglNotification"
                                        android:layout_width="wrap_content"
                                        android:layout_height="match_parent"
                                        android:layout_marginLeft="@dimen/ten_dp"
                                        android:layout_toRightOf="@+id/todoDetailsTxtNotify"
                                        android:background="@android:color/transparent"
                                        android:button="@null"
                                        android:checked="false"
                                        android:text=""
                                        android:textColor="@color/textColorWithoutPrimary"
                                        android:textOff=""
                                        android:textOn="" />

                                </LinearLayout>

                            </RelativeLayout>

                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/todo_details_height"
                                android:orientation="horizontal">

                                <LinearLayout
                                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                                    android:gravity="center"
                                    android:orientation="vertical">

                                    <ImageView
                                        android:id="@+id/todoEditImgAttachment"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:src="@drawable/todo_new_attach" />
                                </LinearLayout>

                                <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                    android:id="@+id/chatEditTxtAttachment"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_marginLeft="@dimen/list_item_content_left_padding"
                                    android:gravity="center|left"
                                    android:text="@string/Attachment" />

                            </RelativeLayout>

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/todo_details_height"
                                android:layout_marginLeft="@dimen/list_item_content_left_padding"
                                android:gravity="center|left"
                                android:orientation="horizontal">

                                <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                    android:id="@+id/chatEditTxtReminder"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_toRightOf="@+id/todoEditImgAttachment"
                                    android:layout_weight="1"
                                    android:gravity="center|left"
                                    android:text="@string/Reminder"
                                    android:visibility="visible" />

                                <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                    android:id="@+id/chatEditTxtForward"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_gravity="center"
                                    android:layout_toRightOf="@+id/todoEditImgAttachment"
                                    android:layout_weight="1"
                                    android:gravity="center|left"
                                    android:text="@string/Forward" />

                                <com.strait.solvenow.Utilities.WithoutPrimaryTextView
                                    android:id="@+id/chatEditTxtRejected"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_toRightOf="@+id/todoEditImgAttachment"
                                    android:layout_weight="1"
                                    android:gravity="center|left"
                                    android:text="@string/Reject" />
                            </LinearLayout>


                        </LinearLayout>
                    </android.support.v7.widget.CardView>

                    <!--    <android.support.v4.widget.SwipeRefreshLayout
                            android:id="@+id/todoSwipeRefresh"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_above="@+id/chatWindowBottomRl">
    -->
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/todoRv"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="@dimen/five_dp"
                        android:paddingLeft="@dimen/activity_vertical_margin"
                        android:paddingRight="@dimen/activity_vertical_margin"

                        android:paddingTop="@dimen/ten_dp"
                        android:visibility="visible"></android.support.v7.widget.RecyclerView>
                    <!--</android.support.v4.widget.SwipeRefreshLayout>-->
                </LinearLayout>
            </android.support.v4.widget.NestedScrollView>
        </LinearLayout>


        <LinearLayout
            android:id="@+id/todoDetailsBottomLl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical">

            <include
                android:id="@+id/todoChatBottomVerticalLine"
                layout="@layout/divider_view_line"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:gravity="center"
                android:background="@color/windowBackground"
                android:paddingLeft="@dimen/activity_vertical_margin"
                android:paddingRight="@dimen/activity_vertical_margin"
                android:visibility="visible">


                <ImageView
                    android:id="@+id/todoChatImgAttachment"
                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:padding="@dimen/icon_padding"
                    android:src="@drawable/chat_attachment"
                    android:visibility="visible" />


                <com.strait.solvenow.Utilities.WithoutEditTextView
                    android:id="@+id/todoChatEdtTextMsg"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/five_dp"
                    android:layout_toLeftOf="@+id/todoChatImgSend"
                    android:layout_toRightOf="@+id/todoChatImgAttachment"
                    android:background="@drawable/chat_window_text_msg_bg"
                    android:hint=""
                    android:maxLines="4"
                    android:minHeight="35dp"
                    android:paddingLeft="@dimen/ten_dp"
                    android:text=""
                    android:textSize="16sp"
                    android:visibility="visible" />

                <ImageView
                    android:id="@+id/todoChatImgSend"
                    android:layout_width="@dimen/avatar_icon_touch_area_size"
                    android:layout_height="@dimen/avatar_icon_touch_area_size"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:gravity="center"
                    android:padding="@dimen/icon_padding"
                    android:src="@drawable/send"
                    android:visibility="visible" />
            </RelativeLayout>
        </LinearLayout>

    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

我在嵌套的Scroll视图中使用了循环视图,但是循环滚动视图中的循环视图没有向下滚动。循环视图在键盘打开时向下滚动,新项目在循环视图中添加。它位于我的代码之上。

2 个答案:

答案 0 :(得分:0)

首先,这是您实施的错误布局技术

根据 android标准,一个布局中的滚动视图不超过两个

为相同的

制作合适的布局

答案 1 :(得分:0)

您应该禁用scrolllerview的滚动:

 recycler.setNestedScrollingEnabled(false);

您还应将recyclerview的高度设置为wrap_content

  

机器人:layout_height = “WRAP_CONTENT”

How to put RecyclerView inside NestedScrollView?