2016-07-25 8 views
0

アクティビティを開くと、アクティビティレイアウトの上部ではなく、RecyclerViewレイアウトの上部が表示されます。アクティビティ開始レイアウトがRecyclerViewのトップに移動します

活動レイアウト.xmlファイル:

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

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:paddingBottom="20dp" 
       android:paddingTop="20dp"> 

      ... 
      <RelativeLayout/> 
      <View /> 
      <LinearLayout/> 
      ... 

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

      </LinearLayout> 
    </ScrollView> 

活動のonCreate:

RecyclerView galleryRecyclerView = (RecyclerView) findViewById(R.id.venue_place_info_gallery_recycler_view); 
    galleryRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(gridLayoutColumns, StaggeredGridLayoutManager.VERTICAL)); 
    VenueGalleryAdapter venueGalleryAdapter = new VenueGalleryAdapter(VenuePlaceInfoActivity.this, images); 
    galleryRecyclerView.setAdapter(venueGalleryAdapter); 

アダプタは非常に簡単です。コンストラクタでイメージを引数として受け取り、後でデータを変更することはできません。 私はすべての種類の設定をRecyclerViewレイアウトに適用しようとしましたが、同じかどうかは同じです。たとえば、次のように

galleryRecyclerView.setNestedScrollingEnabled(false); 
    galleryRecyclerView.setHasFixedSize(true); 
    galleryRecyclerView.setLayoutFrozen(true); 
    galleryRecyclerView.setPreserveFocusAfterLayout(false); 

UPDATE:私はanswer of another questionにテーマに関する詳細情報を発見した

。 setNestedScrollingEnabledをtrueに設定しても、ScrollViewとRecyclerViewが共存できないためです。しかし、それでも私の問題の解決は私にはありません。私はギャラリーRecyclerViewの上にいくつかのものを持っている必要があり、私はすべての画像を下にスクロールしたい(コンテナに入れない)。

+0

スクリーンショットを添付できますか? –

+0

galleryRecyclerView.setPreserveFocusAfterLayout(false)を削除します。 line – vinoth12594

+0

私は、これらの追加パラメータは現時点では削除されていると言いました。私は前にそれらを試したことがありますが、彼らは事を変えませんでした。 – Galya

答えて

0

あなたのレイアウトを見栄え良くするには、その内部の最初の要素としてAppBarLayoutを使用し、2番目の要素としてRecyclerViewを使用してCoordinatorLayoutを使用します。 AppBarLayoutの中には、RecyclerViewの上に置いておきたいものを置いてください。これに似た何か:

<LinearLayout 
    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:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@color/white"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:elevation="0dp"> 

      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/collapsing_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:titleEnabled="false"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:clipChildren="false" 
        android:clipToPadding="false" 
        android:orientation="vertical" 
        android:paddingTop="20dp" 
        app:layout_collapseMode="parallax"> 

        <!-- stuff you want above your recyclerview --> 

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

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

誰かがあなたが欲しいものは何でもビューのレイアウト使用することができ、ちょうど代わりappbarlayoutでツールバーを使用しての、ここに似た何かをします。 AppBarLayoutは拡張垂直LinearLayoutです:http://www.basagee.tk/handling-scrolls-with-coordinatorlayout/

+0

これはおそらく、私が探していたリーンでシンプルな解決策ではありませんが、それは仕事をするので、受け入れられる答えです。私は私のために働いている実際のコードを追加するためにそれを編集しました。 – Galya

関連する問題