【发布时间】:2014-10-08 20:47:28
【问题描述】:
我有一个简单的聊天活动,顶部有一个消息输入框,然后是带有消息列表的滚动视图。打开软键盘时,我希望滚动视图缩小,以便键盘不会覆盖最后一条消息。这是我的 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<TextView
android:id="@+id/chat_with"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Chat with Gordon" />
<RelativeLayout
android:id="@+id/msg_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/chat_with"
android:layout_marginTop="10dp">
<EditText
android:id="@+id/chat_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Type your message" />
<ImageButton
android:id="@+id/chat_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#00000000"
android:src="@+android:drawable/ic_menu_send" />
</RelativeLayout>
<ScrollView
android:id="@+id/chat_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/msg_container"
android:layout_marginTop="15dp"
android:padding="10dp"
android:isScrollContainer="true"
>
<RelativeLayout
android:id="@+id/chat_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/msg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi, how are you?"
android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/msg2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hey! All right"
android:layout_alignParentLeft="true"
android:layout_below="@+id/msg1"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
我只是手动插入了两条消息,但实际应用中会有很多消息。我已经尝试使用 adjustPan|adjustResize 解决方案,但它不起作用,当我触发键盘时,布局没有改变,最后的消息被键盘覆盖。我怎样才能避免这种情况? 感谢您的帮助!
【问题讨论】:
-
一个你应该使用列表视图而不是滚动视图,两个只是滚动到列表的末尾
-
滚动到列表末尾不是问题,我可以通过编程方式完成。问题是键盘覆盖了消息。为什么我不应该使用滚动视图?
-
阅读列表视图的作用并找出为什么要使用它developer.android.com/guide/topics/ui/layout/listview.html。键盘打开时无法显示最后一条消息,消息可能真的很长
-
我知道列表视图是什么,但我仍然不明白为什么它会缩小而滚动视图不会。但我会阅读更多内容。
-
我从来没有说过我会说没有办法显示整个消息,并且动态显示许多消息时滚动视图在这里不合适
标签: android android-layout android-scrollview