滚动无法在CoordinatorLayout

时间:2016-06-28 05:38:31

标签: android scroll android-recyclerview android-coordinatorlayout

我在CoordinatorLayout中有RecyclerView和LinearLayout。对于RecyclerView滚动工作正常,但我希望上面的内容在屏幕上滚动。请指导我需要做的更改或任何我做错的事情请指导我。

my activity_article_polls.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="in.passionconnect.application.ArticlePolls">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/landing_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="440dp"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

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

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

    <include layout="@layout/content_article_polls" />

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

和我的content_article_polls.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="in.passionconnect.application.ArticlePolls"
    tools:showIn="@layout/activity_article_polls">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/landing_list"
            android:orientation="vertical"
            app:layout_scrollFlags="scroll|enterAlways">

            <LinearLayout
                android:id="@+id/layout_filters"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/colorPrimary"
                android:gravity="center"
                android:orientation="horizontal"
                android:visibility="visible"
                android:weightSum="3">


                <CheckBox
                    android:id="@+id/chk_date"
                    style="@style/roboregular"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="#ffffff"
                    android:text="Newest"
                    android:textColor="@color/white" />

                <CheckBox
                    android:id="@+id/chk_random"
                    style="@style/roboregular"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="#ffffff"
                    android:text="Random"
                    android:textColor="@color/white" />

                <CheckBox
                    android:id="@+id/chk_popular"
                    style="@style/roboregular"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="#ffffff"
                    android:text="Popularity"
                    android:textColor="@color/white" />

            </LinearLayout>


            <LinearLayout
                android:id="@+id/card_summary_read_more_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="visible">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/card_background_gradient_overlay"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/landing_card_imageview_height"
                        android:adjustViewBounds="true"
                        android:background="@drawable/card_gradient_overlay"
                        android:scaleType="centerCrop" />

                    <TextView
                        android:id="@+id/article_poll_title"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="left|bottom"
                        android:padding="10dp"
                        android:text="Top 3 Highest Grossing Hollywood Movies"
                        android:textColor="@color/white"
                        android:textSize="14sp" />
                </FrameLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:paddingLeft="10dp">

                        <in.passionconnect.application.view.RoundedImageView
                            android:id="@+id/card_author_icon"
                            android:layout_width="40dp"
                            android:layout_height="40dp"
                            android:layout_centerHorizontal="true"
                            android:padding="12dp"
                            android:scaleType="centerCrop"
                            android:src="@drawable/lion" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical"
                            android:paddingLeft="10dp">

                            <TextView
                                android:id="@+id/article_author"
                                style="@style/robobold"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:ems="8"
                                android:text="Prasanth"
                                android:textColor="@color/dark_gray"
                                android:textSize="15sp" />

                            <TextView
                                android:id="@+id/article_author_desn"
                                style="@style/roboregular"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="developer at varchas technologies"
                                android:textColor="@color/dark_gray"
                                android:textSize="12sp" />

                            <TextView
                                android:id="@+id/article_date"
                                style="@style/roboregular"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="12th March 2016 06:09:06 PM"
                                android:textColor="@color/dark_gray"
                                android:textSize="12sp" />
                        </LinearLayout>

                        <TextView
                            android:id="@+id/article_author_id"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@color/dark_gray"
                            android:visibility="invisible" />

                        <TextView
                            android:id="@+id/article_title_id"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@color/dark_gray"
                            android:visibility="invisible" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/txt_follow"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_gravity="center"
                        android:layout_marginRight="10dp"
                        android:background="@drawable/follow_border"
                        android:padding="10dp"
                        android:text="Follow"
                        android:textColor="#b7492b"
                        android:textSize="15sp" />

                    <TextView
                        android:id="@+id/txt_unfollow"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_gravity="center"
                        android:background="@drawable/follow_border"
                        android:padding="10dp"
                        android:text="Following"
                        android:textColor="#b7492b"
                        android:textSize="15sp"
                        android:visibility="gone" />

                </RelativeLayout>

                <TextView
                    android:id="@+id/card_summary"
                    style="@style/roboregular"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:lineSpacingExtra="2.5dp"
                    android:padding="10dp"
                    android:text="@string/card_summary"
                    android:textColor="@color/dark_gray"
                    android:textSize="16sp"
                    android:visibility="visible" />

            </LinearLayout>
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/landing_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

我也尝试过,只有我的recyclerview滚动。我想滚动整个屏幕和recyclerview。 在此先感谢

2 个答案:

答案 0 :(得分:3)

Atlast我尝试并修复了滚动问题。我提到了This link

只需将高度设置为我的Recyclerview android:minHeight="840dp"

content_article_polls.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="in.passionconnect.application.ArticlePolls"
    tools:showIn="@layout/activity_article_polls">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/landing_list"
            android:orientation="vertical"
            app:layout_scrollFlags="scroll|enterAlways">

            <LinearLayout
                android:id="@+id/layout_filters"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/colorPrimary"
                android:gravity="center"
                android:orientation="horizontal"
                android:visibility="visible"
                android:weightSum="3">


                <CheckBox
                    android:id="@+id/chk_date"
                    style="@style/roboregular"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="#ffffff"
                    android:text="Newest"
                    android:textColor="@color/white" />

                <CheckBox
                    android:id="@+id/chk_random"
                    style="@style/roboregular"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="#ffffff"
                    android:text="Random"
                    android:textColor="@color/white" />

                <CheckBox
                    android:id="@+id/chk_popular"
                    style="@style/roboregular"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:buttonTint="#ffffff"
                    android:text="Popularity"
                    android:textColor="@color/white" />

            </LinearLayout>


            <LinearLayout
                android:id="@+id/card_summary_read_more_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="visible">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/card_background_gradient_overlay"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/landing_card_imageview_height"
                        android:adjustViewBounds="true"
                        android:background="@drawable/card_gradient_overlay"
                        android:scaleType="centerCrop" />

                    <TextView
                        android:id="@+id/article_poll_title"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="left|bottom"
                        android:padding="10dp"
                        android:text="Top 3 Highest Grossing Hollywood Movies"
                        android:textColor="@color/white"
                        android:textSize="14sp" />
                </FrameLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="10dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:paddingLeft="10dp">

                        <in.passionconnect.application.view.RoundedImageView
                            android:id="@+id/card_author_icon"
                            android:layout_width="40dp"
                            android:layout_height="40dp"
                            android:layout_centerHorizontal="true"
                            android:padding="12dp"
                            android:scaleType="centerCrop"
                            android:src="@drawable/lion" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical"
                            android:paddingLeft="10dp">

                            <TextView
                                android:id="@+id/article_author"
                                style="@style/robobold"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:ems="8"
                                android:text="Prasanth"
                                android:textColor="@color/dark_gray"
                                android:textSize="15sp" />

                            <TextView
                                android:id="@+id/article_author_desn"
                                style="@style/roboregular"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="developer at varchas technologies"
                                android:textColor="@color/dark_gray"
                                android:textSize="12sp" />

                            <TextView
                                android:id="@+id/article_date"
                                style="@style/roboregular"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="12th March 2016 06:09:06 PM"
                                android:textColor="@color/dark_gray"
                                android:textSize="12sp" />
                        </LinearLayout>

                        <TextView
                            android:id="@+id/article_author_id"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@color/dark_gray"
                            android:visibility="invisible" />

                        <TextView
                            android:id="@+id/article_title_id"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@color/dark_gray"
                            android:visibility="invisible" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/txt_follow"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_gravity="center"
                        android:layout_marginRight="10dp"
                        android:background="@drawable/follow_border"
                        android:padding="10dp"
                        android:text="Follow"
                        android:textColor="#b7492b"
                        android:textSize="15sp" />

                    <TextView
                        android:id="@+id/txt_unfollow"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_gravity="center"
                        android:background="@drawable/follow_border"
                        android:padding="10dp"
                        android:text="Following"
                        android:textColor="#b7492b"
                        android:textSize="15sp"
                        android:visibility="gone" />

                </RelativeLayout>

                <TextView
                    android:id="@+id/card_summary"
                    style="@style/roboregular"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:lineSpacingExtra="2.5dp"
                    android:padding="10dp"
                    android:text="@string/card_summary"
                    android:textColor="@color/dark_gray"
                    android:textSize="16sp"
                    android:visibility="visible" />

            </LinearLayout>
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/landing_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:minHeight="840dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

答案 1 :(得分:0)

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.passionconnect.application.ArticlePolls">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

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

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

<include layout="@layout/content_article_polls" />

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

您要包含的其他布局应如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView    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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="in.passionconnect.application.ArticlePolls"
tools:showIn="@layout/activity_scrolling">

<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">

 <android.support.v7.widget.RecyclerView
    android:id="@+id/landing_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="440dp"
    android:clipToPadding="false"/>

<LinearLayout
    android:layout_below="@+id/landing_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_scrollFlags="scroll|enterAlways">
    <LinearLayout
        android:id="@+id/layout_filters"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:orientation="horizontal"
        android:visibility="visible"
        android:weightSum="3">


        <CheckBox
            android:id="@+id/chk_date"
            style="@style/roboregular"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:buttonTint="#ffffff"
            android:text="Newest"
            android:textColor="@color/white" />

        <CheckBox
            android:id="@+id/chk_random"
            style="@style/roboregular"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:buttonTint="#ffffff"
            android:text="Random"
            android:textColor="@color/white" />

        <CheckBox
            android:id="@+id/chk_popular"
            style="@style/roboregular"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:buttonTint="#ffffff"
            android:text="Popularity"
            android:textColor="@color/white" />

    </LinearLayout>


    <LinearLayout
        android:id="@+id/card_summary_read_more_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="visible">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/card_background_gradient_overlay"
                android:layout_width="match_parent"
                android:layout_height="@dimen/landing_card_imageview_height"
                android:adjustViewBounds="true"
                android:background="@drawable/card_gradient_overlay"
                android:scaleType="centerCrop" />

            <TextView
                android:id="@+id/article_poll_title"
                style="@style/robobold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_gravity="left|bottom"
                android:padding="10dp"
                android:text="Top 3 Highest Grossing Hollywood Movies"
                android:textColor="@color/white"
                android:textSize="14sp" />
        </FrameLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingLeft="10dp">

                <in.passionconnect.application.view.RoundedImageView
                    android:id="@+id/card_author_icon"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_centerHorizontal="true"
                    android:padding="12dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/lion" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:paddingLeft="10dp">

                    <TextView
                        android:id="@+id/article_author"
                        style="@style/robobold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:ems="8"
                        android:text="Author name"
                        android:textColor="@color/dark_gray"
                        android:textSize="15sp" />

                    <TextView
                        android:id="@+id/article_author_desn"
                        style="@style/roboregular"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="author"
                        android:textColor="@color/dark_gray"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@+id/article_date"
                        style="@style/roboregular"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="12th March 2016 06:09:06 PM"
                        android:textColor="@color/dark_gray"
                        android:textSize="12sp" />
                </LinearLayout>

            </LinearLayout>

            <TextView
                android:id="@+id/txt_follow"
                style="@style/robobold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_gravity="center"
                android:layout_marginRight="10dp"
                android:background="@drawable/follow_border"
                android:padding="10dp"
                android:text="Follow"
                android:textColor="#b7492b"
                android:textSize="15sp" />

        </RelativeLayout>
    </LinearLayout>
  </LinearLayout>
 </RelativeLayout>
</android.support.v4.widget.NestedScrollView>