2016-01-13 101 views
0

回收站視圖獲取裏面的ImageView和imageview的滾動保持stationary.My要求是既滾動視圖時recyclerview是scrolled.The XML我已經寫了下面給出:NestedScrollView與ImageView的和回收視圖

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

     <LinearLayout 
      android:gravity="center_vertical" 
      android:id="@+id/profileLayout" 
      android:layout_width="match_parent" 
      android:layout_height="180dp" 
      android:background="@color/primary_color" 
      android:orientation="vertical" 
      android:padding="10dp"> 

      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/profile_image" 
       android:layout_width="96dp" 
       android:layout_height="96dp" 
       android:src="@drawable/profile_user" 
       app:border_color="#ffffff" 
       app:border_width="2dp" /> 

      <TextView 
       android:id="@+id/fullNameTextView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:textColor="@color/primary_color" /> 
     </LinearLayout> 


    <android.support.v7.widget.RecyclerView 
      android:id="@+id/drawerList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/myDrawerBackground" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

    </LinearLayout> 

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

我如何實現這種類型的滾動?

+0

https://github.com/chrisbanes/cheesesquare看看這個代碼,它可以幫助你 –

+0

@LalitPratapSingh NestedScrollView在庫使用的TextView包裹在裏面Cardview那不是我正在尋找的! –

回答

2

我認爲你應該使用CoordinatorLayout爲了這個目的,你可以把你的圓形ImageViewCollapsingToolbarLayout &你也可以用它來設置你的標題,而不是你的TextView這是由fullNameTextView ID如下規定的:

XML:

<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"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/collapsible_app_bar_height" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/gradient_banner" 
      app:contentScrim="@color/background_content_frame" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/profile_image" 
       android:layout_width="96dp" 
       android:layout_height="96dp" 
       android:src="@drawable/profile_user" 
       app:border_color="#ffffff" 
       app:border_width="2dp" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/collapsible_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:layout_collapseMode="pin"/> 

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

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

    <android.support.v7.widget.RecyclerView 
      android:id="@+id/drawerList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/myDrawerBackground" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

的Java:

CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 
collapsingToolbar.setTitle("Title"); 

參考:https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

0
<RelativeLayout  
    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:background="@color/cardview_light_background" 
    android:orientation="vertical"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/scrollView" 
     tools:ignore="UselessParent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      tools:ignore="ExtraText" 
      android:weightSum="1" > 

      <ImageView 
       android:id="@+id/image_offer" 
       android:layout_width="match_parent" 
       android:layout_height="250dp" 
       android:scaleType="fitXY" 
       app:srcCompat="@drawable/kuhnyamain" 
       tools:ignore="ContentDescription" /> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerView" 
       android:layout_marginTop="250dp" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </android.support.v7.widget.RecyclerView> 

     </LinearLayout> 

    </ScrollView> 

</RelativeLayout>