2017-09-26 5 views
0

私はRecyclerViewを使って送受信されたメッセージを表示するチャット画面のレイアウトで作業していますが、私が直面している問題はRecyclerViewで画面全体を見て、私は下にスクロールしたり、スクロールしなければならない他のメッセージを見ることができます。私はメッセージを縦に並べて表示したい。ここでRecyclerViewは1つのメッセージを表示するために全画面表示しています

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/chatparent" 
    android:background="@color/background"> 
    <include layout="@layout/chattoolbar"/> 





    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rv_messages" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:scrollbars="vertical" 
     android:scrollbarStyle="outsideOverlay"/> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom"> 




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




      <FrameLayout 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_weight="0.80" 
       android:background="@color/colorPrimary" /> 

      <FrameLayout 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_weight="0.20" 
       android:background="@color/black"/> 

    </LinearLayout> 


     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/rl_typing" 
      android:background="@drawable/chatbox" 
      android:orientation="horizontal" 
      android:paddingLeft="5dp" 
      android:paddingRight="10dp" 
      android:layout_marginStart="15dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:layout_marginEnd="2dp" 
      > 


      <Button 
       android:layout_width="20dp" 
       android:layout_height="20dp" 
       android:background="@drawable/ic_emoticons" 
       android:layout_marginTop="8dp" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:gravity="bottom" 
       android:id="@+id/btn_emoji" 
       /> 



      <EditText 
       android:layout_width="190dp" 
       android:layout_height="wrap_content" 
       android:inputType="textMultiLine" 
       android:minLines="1" 
       android:maxLines="20" 
       android:lines="8" 
       android:imeActionId="@+id/send" 
       android:imeActionLabel="actionSend" 
       android:imeOptions="actionSend" 
       android:scrollbars="vertical" 
       android:textColor="@color/monsoon" 
       android:textColorHint="@color/dark_gray" 
       android:id="@+id/et_message" 
       android:textSize="13sp" 
       android:hint=" Type Your Message Here..." 
       android:layout_toEndOf="@id/btn_emoji" 
       tools:ignore="HardcodedText" /> 



      <Button 
       android:layout_width="20dp" 
       android:layout_height="20dp" 
       android:background="@drawable/ic_attachment" 
       android:layout_marginTop="8dp" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:gravity="bottom" 
       android:id="@+id/btn_attach" 
       android:layout_toEndOf="@id/et_message"/> 


      <Button 
       android:layout_width="20dp" 
       android:layout_height="20dp" 
       android:background="@drawable/ic_camera" 
       android:layout_marginTop="8dp" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:id="@+id/btn_camera" 
       android:layout_toEndOf="@id/btn_attach"/> 


     </RelativeLayout> 

     <Button 
      android:layout_width="30dp" 
      android:layout_height="35dp" 
      android:id="@+id/btn_send" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="7.5dp" 
      android:layout_centerHorizontal="true" 
      android:layout_marginStart="3dp" 
      android:layout_toEndOf="@id/rl_typing" 
      android:background="@drawable/ic_send" /> 




    </RelativeLayout> 
</LinearLayout> 

recyclerView_item.xmlです: - - : はここに私のXMLコードである。ここ

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="5dp" 
    android:paddingTop="5dp" 
    android:paddingLeft="10dp"> 


    <TextView 
     android:id="@+id/username" 
     style="?android:textAppearanceMedium" 
     android:textColor="?android:textColorPrimary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:singleLine="true" 
     android:textStyle="bold"/> 

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


    <TextView 
     android:id="@+id/txtOther" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="16dp" 
     android:textColor="@color/black" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" 
     android:paddingTop="5dp" 
     android:paddingBottom="5dp" 
     android:background="@drawable/chat_in"/> 

    <TextView 
     android:id="@+id/message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/chat_out" 
     android:paddingBottom="5dp" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" 
     android:paddingTop="5dp" 
     android:textColor="@color/white" 
     android:textSize="16dp" /> 

     <TextView 
      android:id="@+id/lblDate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="12dp" 
      android:textColor="@color/colorprimarylight" 
      android:textStyle="italic" 
      android:padding="5dp" 
      /> 

</LinearLayout> 



</LinearLayout> 

は、2つのメッセージの間に生産されてどのくらいのスペースあなたが見ることが可能なスクリーンショットです。 Screenshot

+0

をwrap_contentするためにあなたの「メイン」のLinearLayoutの高さと幅match_parentを設定する必要がありますを添付してくださいrecyclerView項目XMLもここ – Raja

+1

変更してください。 – nomag

+0

をwrap_contentするmatch_parentからのアイテムの高さは、私がrecyclerView_item.xml' 'でrecyclerView項目XML – param

答えて

2

リサイクラの子ビューでは、xmlルートを "wrap_content"に設定します。フラグmatch_parentを設定すると、すべての領域が必要になり、親ビューをスクロールする必要があります。

+0

ためlayout_height =「wrap_contentを」'私のrecyclerview item.xmlファイルのro高さはmatch_parentでした。 –

+0

問題はありません、アプリの幸運 – Unii

5

セットrecyclerview項目の主なレイアウトの高さ「wrap_content」

+0

Thanx Pooja ...私は同じことを考え出しました。 –

0

recyclerView_item.xmlで、あなたは

関連する問題