2015-10-11 10 views
12

私は動的コンテンツを表示するRecyclerViewを持っています。私は他のビューの間にこのRecyclerViewを表示したいと思います。私が動作していないようです試してみて、RecyclerViewは全体のスペースを取るように見えるものは何でも、しかしRecyclerViewの上下のビュー

View 
RecyclerView 
View 

:たとえば、1ビューは、上記とRecyclerViewの下に表示された1つのビュー表示しました。私は問題がwrap_content issueにあると信じていますが、私はthis custom LinearLayoutManagerのような提案された解決策を試しましたが、私の問題を解決していないようです。

試み:

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

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

     <!-- AppBar works fine; no issue here --> 
     <android.support.design.widget.AppBarLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:id="@+id/app_bar_layout"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_height="?attr/actionBarSize" 
       android:layout_width="match_parent" 
       app:layout_collapseMode="pin"/> 

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

     <!-- Not displaying; Tried different views --> 
     <com.chrynan.taginput.view.TextInputWrapper 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/edit_text_container"> 
      <AutoCompleteTextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/edit_text"/> 
     </com.chrynan.taginput.view.TextInputWrapper> 

     <!-- Takes up entire screen space --> 
     <android.support.v4.widget.SwipeRefreshLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/swipe_refresh"> 

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

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

     <!-- Not displaying --> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/text_view"/> 

    </LinearLayout> 

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

質問:は、上記のビューとRecyclerView以下のビューを配置して表示する方法はありますか?もしそうなら、どうですか?またはListViewを使用する方が良いですか?

答えて

25

何?

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

    <View 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

    <RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 
+0

私のレイアウトが私が与えた例よりもやや複雑であるか、またはRecyclerViewの既知のバグのために、単にlayout_weightを追加しても機能しませんでした。しかし、私はRecyclerViewの代わりにListViewを使い、LayoutViewをListViewに追加することで、望みの効果が得られました。 – chRyNaN

+1

偉大な答え。これは私のためにうまくいった。 – Mythul

+0

優れた超大... –

1

これはあなたの典型的な解決策ではないかもしれませんが、やはり試してみることができます。

LinearLayoutの代わりにRelativeLayoutを使用し、SwipeRefreshLayoutの上下のパディングをビューの高さに設定する方法は次のとおりです。 weightの使用状況について

<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:fitsSystemWindows="true"> 

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

    <!-- your app bar --> 

    <!-- Not displaying; Tried different views --> 
    <com.chrynan.taginput.view.TextInputWrapper 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:layout_alignParentTop="true" 
     android:id="@+id/edit_text_container"/> 

    <!-- Takes up entire screen space --> 
    <android.support.v4.widget.SwipeRefreshLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="150dp" 
     android:paddingBottom="250dp" 
     android:id="@+id/swipe_refresh"> 

     <android.support.v7.widget.RecyclerView 

      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/recycler_view"/> 

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

    <!-- bottom view --> 
    <TextView 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:id="@+id/text_view"/> 

</RelativeLayout> 

+1

残念ながら、私のトップビューとボトムビューはサイズを動的に変更するため、これは実行可能な解決策ではありません。 – chRyNaN

+0

パディングを動的にリセットしないのはなぜですか? – Ari

+0

パディングが動的にうまくいかなかったので私にとってはうまくいかなかった。 ListViewを代わりに使用し、その上にlayout_weight属性を追加しました。これは私の望む効果をもたらしました。ご協力いただきありがとうございます。 – chRyNaN

1

RecyclerViewのための使用ヘッダーとフッター、Recyclerviewアダプタでビュータイプを使用し、ヘッダーとフッターを追加view.The、あなたが直面している問題は、1つのレイアウトであるため、複数のscollviewのものであり、最善の解決策は、ヘッダーとフッターを使用することですこれは単一のスクロールビューとして作成されます。詳細についてはこのリンクを参照してくださいhttps://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type?rq=1

関連する問題