感谢您的关注, 我正在创建一个聊天应用程序。它适用于大部分。 我遇到的唯一问题是滚动。 我使用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