I have created a chatroom where user can discuss on several Topic. I'm using a Scrollview inside RelativeLayout which contains chatConversation The Porblem is when user opens app then he has to scroll to the Bottom HImself to chat or view the new chat discussion.
How can I force scrollview to start at Bottom when activity is started..
Below is my layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.NoActionBar"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/main_chat"
app:titleTextAppearance="@style/Toolbar.TitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#F0791F"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/ic_people_outline_black_24dp"/>
<Button
android:id="@+id/btn_send"
android:layout_width="42dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_send_black_24dp" />
<EditText
android:id="@+id/msg_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/btn_send"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/btn_send"
android:layout_toStartOf="@+id/btn_send"
android:background="@null"
android:hint="Write a message" />
<ScrollView
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:transcriptMode="alwaysScroll"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/btn_send"
android:layout_below="@+id/main_chat"
android:layout_alignRight="@+id/btn_send"
android:layout_alignEnd="@+id/btn_send">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="2dp"
android:layout_weight="2"
android:autoLink="all" />
</ScrollView>
<View
android:layout_above="@+id/msg_input"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/darker_gray"/>
</RelativeLayout>
I already tried using
final ScrollView scrollLayout = ((ScrollView) findViewById(R.id.scrollView));
scrollLayout.post(new Runnable() {
@Override
public void run() {
scrollLayout.fullScroll(ScrollView.FOCUS_DOWN);
}
});
But it doesn't work either.
Please Help