2016-05-15 9 views
2

私のrecyclerviewにはカスタムデザインの背景があり、基本的にいくつかのデザインノイズ(whatsappのようなもの)が追加されています。 私が達成したいのは、recyclerviewをスクロールすると、recyclerviewの項目の半分の速度で背景がスクロールすることです。視差スクロールバックグラウンドリサイクルビュー

これが可能かどうか、またどうすればいいですか?

+0

あなたには、いくつかのコードを投稿することができます: verticall変位によると、次のようなXMLコードのコードを見て、このscrollView.smoothScrollBy(0,dy); のようにスクロールビューをスクロールすることができますか? – Haroon

+0

これは、実装メソッドの標準的なrecyclerviewです。行には画面の中央にイメージビューが含まれているため、画面の残りの部分には背景が書き込まれます。 15種類以上のビュータイプで作業しているため、コードがあまりにも多く投稿されています。 – user5102612

答えて

2

これはかなり達成可能です。あなたのリサイクラビューを10,000ピクセルだけ垂直方向にスクロールすることができます、あなたの背景を5000ピクセルだけ変換したいですか?これが当時の場合は、非常に重いイメージファイルを使用する必要があります。このイメージファイルは、あなたの場合には、メモリが不足しています。 それ以外の場合は、frameLayout内にScrollViewビューとリサイクラビューを保持します。 次に、あなたのアクティビティ/フラグメントで、scrollChangeリスナーをrecyclerViewに追加します(リサイクルビューの置換、特にdyが必要です)。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

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

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

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
       <!--your imageView that is bigger than screen height comes here--> 

      </LinearLayout> 
     </ScrollView> 
     <android.support.v7.widget.RecyclerView 
      android:background="@android:color/transparent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
    </FrameLayout> 
</LinearLayout> 

Also please feel free to show me your progress and also if you are stuck. 
+0

ありがとう、完璧に動作します! – user5102612