0

我在CoordinatorLayout中有RecyclerView和LinearLayout。對於RecyclerView滾動工作正常,但我想上面的內容在屏幕上滾動。請指導我需要做什麼更改或任何即時做錯請引導我。滾動不能在CoordinatorLayout中工作

我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

使用NestedScrollView作爲家長您recyclerview和LinearLayout中 – SaravInfern

+0

你們是不是要做到這一點https://開頭指南.codepath.com /安卓/處理-卷軸與 - CoordinatorLayout? – Mani

+0

如果您希望recyclerview和包含的佈局都可以滾動,您可以嘗試下面的代碼。 – Drv

回答

2

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> 
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> 
+0

recyclerview隱藏,我無法看到 –

+0

我實現了你的代碼,仍然沒有工作。我嘗試了很多方法,只有recyclerview滾動不超過部分 –

+0

請粘貼您的整個佈局,以便我可以理解您要在回收站查看上面滾動的內容。 – Drv

相關問題