感謝您的關注, 我正在創建一個聊天應用程序。它適用於大部分。 我遇到的唯一問題是滾動。 我使用EditText從服務器發佈新消息。Android:自動向下滾動EditTextView以獲取聊天應用程序
的方法
msg = msg + "\n" + newMsg
EditText.setText(msg)
我需要新的文本,一旦談到正在舊文本可見。
所以我認爲最好的辦法是自動向下滾動一旦視圖更新。
有沒有簡單的方法來做到這一點?像佈局也許?
再次感謝!佈局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="send"
/>
<EditText
android:id="@+id/msgBox"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/sendButton"
android:gravity="left"
android:longClickable="false"
/>
<EditText
android:id="@+id/chatBox"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:editable="false"
android:layout_above="@+id/msgBox"
android:scrollbars="vertical"
android:gravity="left|top"
android:isScrollContainer="true"
android:cursorVisible="false"
android:longClickable="false"
android:clickable="false"
android:autoLink="all"
/>
</RelativeLayout>
這可以一直滾動到底部!使用Jignesh的XML佈局http://stackoverflow.com/questions/5101448/android-auto-scrolling-down-the-edittextview-for-chat-apps/5101616#5101616然後SenorCarbone的代碼如上。 – 2011-11-18 04:41:49