Reputation:
i am working on a layout for chat screen in which i am using RecyclerView to show messages sent and receive by user but the problem which i am facing is RecyclerView is showing only one message in whole screen and to see other message i have to scroll down or scroll up. i want to show messages next to eachother vertically. Here is my xml code:-
<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>
Here is the recyclerView_item.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>
Here is the screenshot in which you can see how much space it is producing in between two messages.
Upvotes: 0
Views: 2830
Reputation: 402
In recyclerView_item.xml, you must set your 'main' LinearLayout's height and width match_parent to wrap_content
Upvotes: 0
Reputation: 1617
In child view of recyclerView set xml root to "wrap_content". If you set a flag match_parent it will take all space and you need to scroll your parent view.
Upvotes: 2