2015-12-17 27 views
19

私は、LinearLayoutとRecyclerViewを含むNestedScrollViewを持っています(どちらもRelativeLayout内にあります)。NestedScrollViewは、Recyclerviewの上にスクロールします。

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

    <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/lay_account"> 


     <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/white" 
       android:paddingTop="10dp" 
       android:id="@+id/lay_total" 
       android:paddingBottom="10dp"> 

      <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/total" 
        android:id="@+id/lblTotal" 
        android:textSize="@dimen/text_medium" 
        android:layout_marginLeft="20dp" 
        android:textColor="@color/dark_eurakostheme_color" 
        android:textStyle="bold"/> 


      <LinearLayout 
        android:orientation="horizontal" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_vertical|center_horizontal"> 

       <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/txtTotalAmount" 
         android:textSize="@dimen/text_extra_extra_large" 
         android:gravity="center_horizontal" 
         android:textColor="@color/eurakostheme_color"/> 

       <ImageView 
         android:layout_width="@dimen/icon_extra_extra_large" 
         android:layout_height="match_parent" 
         android:id="@+id/imageView3" 
         android:src="@drawable/coin_eurakos"/> 
      </LinearLayout> 

     </LinearLayout> 

     <View 
       android:layout_width="fill_parent" 
       android:layout_height="1dp" 
       android:id="@+id/divisor" 
       android:background="@color/dividerColor" 
       android:layout_alignBottom="@+id/lay_total"/> 

     <android.support.v7.widget.RecyclerView 
       android:layout_below="@id/lay_total" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/rclBasketAmounts" 
       android:background="@android:color/white" 
       android:padding="10dp"> 
     </android.support.v7.widget.RecyclerView> 

    </RelativeLayout> 

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

RecyclerViewにデータをロードした後、私はそれを変更する必要があるが、このように、プログラムの高さだ:データがNestedScrollViewのスクロールのロードが終了したときに問題がある

RelativeLayout.LayoutParams lay_params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
    50 + ((int) (baskets.length * getResources().getDimension(R.dimen.list_height_small)))); 

lay_params.addRule(RelativeLayout.BELOW, lay_total.getId()); 
recyclerView.setLayoutParams(lay_params); 
recyclerView.setAdapter(new ListBasketAmountAdapter(baskets)); 

自動的に先頭にスクロールRecyclerView、その上にLinearLayoutを隠します。何か案は?

ありがとうございました。

+0

あなたは 'ScrollView'で' RecyclerView'を置くべきではありません。 –

+1

修正プログラムを見つけましたか?私も同じ問題があります –

+0

まだ、ほとんどすべてを試しました – kevings14

答えて

75

数日後、私はこの問題の解決策を見つけました。あなたはちょうどこのようScrollViewの下にある最初のレイアウトにdescendantFocusabilityを追加する必要があります。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/lay_account" 
    android:descendantFocusability="blocksDescendants"> 
+0

検索の長い1日後の私のケースでは、あなたの答えは問題を解決しましたが、私は固定サイズのImageView(この効果を引き起こす)を含む垂直なLinearLayoutを持っています。 –

+1

この解決策は動作しますが、子ビューに 'EditText'があり、それがフォーカス可能でない場合は覚えておいてください。 –

10

kevings14によって与えられた解決策は動作しますが、それは私の場合は有用ではなかったです。私は、スクロールビューの下のメインレイアウトに

android:descendantFocusability="blocksDescendants" 

を追加NestedScrollViewEditTextRecyclerView +カップルを、しました。私はEditTextに集中できませんでした。

私はこの解決策を思いつきました。これは私のために働いていました。私の場合は

<RelativeLayout 
    android:layout_width="match_parent" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:layout_height="wrap_content"> 
2

、私はNestedScrollView内の複数のRecyclerViewを使用しています。その後、 私のためには動作しません。だから私のソリューションは、私のデータ更新が完了し、その後、私はちょうどトップにスクロールすると、ある

yourList.setAdapter(yourListAdapter); 

scrollView.post(new Runnable() { 
    @Override 
    public void run() { 
     scrollView.fullScroll(ScrollView.FOCUS_UP); 
     //scrollView.scrollTo(0,0); 
    } 
}); 
関連する問題