1

Im trying to build a chat app and although my listview does append a messages as they come in, I cannot access the messages that are older or hidden from the screen. The listview does not want to scroll and just display the amount of messages that fit onto the screen which are the most recent ones. It still does not work. Something to note i have a expanding toolbar and this layout is on a fragment

Edit: To fix this problem of the listview not scrolling add

android:nestedScrollingEnabled="true"

to the listview that is not scrolling Code:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main"
android:weightSum="1"
android:background="@drawable/bg_messages">


<ListView
    android:id="@+id/list_view_messages"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:divider="@null"
    android:stackFromBottom="true"
    />


<LinearLayout
    android:id="@+id/llMsgCompose"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:orientation="horizontal"

    android:weightSum="3"
    android:layout_gravity="center|bottom"
    >

    <EditText
        android:id="@+id/inputMsg"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="2"
        android:paddingLeft="6dp"
        android:paddingRight="6dp" />

    <Button
        android:id="@+id/btnSend"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="@color/white"
        android:text="Send" />
</LinearLayout>

Abdul Mirza
  • 23
  • 2
  • 9

1 Answers1

0

i might be think that weight is giving the problem here.I suggest that try to use RelativeLayout as your Parent Layout.Once just try to replace your Xml with this code below.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main"
android:background="@drawable/bg_messages">


<ListView
android:layout_above="@+id/llMsgCompose"
android:id="@+id/list_view_messages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
/>


<LinearLayout
android:id="@+id/llMsgCompose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:layout_gravity="center|bottom"
android:layout_alignParentBottom="true"
android:weightSum="3"   
>

<EditText
    android:id="@+id/inputMsg"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="2"
    android:paddingLeft="6dp"
    android:paddingRight="6dp" />

<Button
    android:id="@+id/btnSend"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/white"
    android:text="Send" />
 </LinearLayout>

Thanks, its Might be this help You.

Shubhank Gupta
  • 833
  • 2
  • 15
  • 35