2016-05-05 8 views
0

は私のxmlファイルです:RecyclerView私は注射していませんか?ここで

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:baselineAligned="false" 
    android:orientation="horizontal"> 


    <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:dividerHeight="10dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:showIn="@layout/content_main"> 


     <android.support.v4.widget.DrawerLayout 

      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/DrawerLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:elevation="7dp"> 


      <!-- Framelayout to display Fragments --> 
      <FrameLayout 
       android:id="@+id/frame_container" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

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


       <include 
        android:id="@+id/tool_bar" 
        layout="@layout/tool_bar"></include> 
      </LinearLayout> 


      <android.support.v7.widget.RecyclerView 
       android:id="@+id/RecyclerView" 
       android:layout_width="320dp" 
       android:layout_height="match_parent" 
       android:layout_gravity="left" 

       android:background="#ffffff" 
       android:scrollbars="vertical"> 


      </android.support.v7.widget.RecyclerView> 


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


    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/threadRecyclerView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" /> 


    </RelativeLayout> 
</LinearLayout> 

私はこの設計を行った主な理由は、適切に

<android.support.v7.widget.RecyclerView 
       android:id="@+id/threadRecyclerView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:scrollbars="vertical" /> 

を表示しようとしました。しかし、それがまったく表示されていないとき。 2つの相対的なレイアウトを追加する前に、1つの相対レイアウトがあり、recyclerviewが表示されましたが、リストのすべての項目に対してmatch_parentを修正できませんでした。ビューを正しく表示するにはどうしたらいいですか?

+0

については、最初に適切な説明で質問を更新してください。今度は、DrawerLayoutを親レイアウトとして配置してみてください。それを実装します。 –

答えて

2

問題はおそらくRecyclerViewlayout_height="wrap_content"と関係があります。 RecyclerViewを正しく使用するには、wrap_contentsetAutoMeasureEnabled(true)を使用する必要があります。

ここでは例です:

RecyclerView threadRecyclerView = (RecyclerView)findViewById(R.id.threadRecyclerView); 
threadRecyclerView.getLayoutManager().setAutoMeasureEnabled(true); 

そして、あなたのあなたのXMLは次のようになります。

<android.support.v7.widget.RecyclerView 
    android:id="@+id/threadRecyclerView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" 
    app:layoutManager="LinearLayoutManager"/> 

役に立てば幸いです。 :)

Android Support Library +23.2

関連する問題