【发布时间】:2016-04-29 04:15:36
【问题描述】:
我正在制作一个底部有一个发送消息框的聊天活动。发送消息框应始终可见并且始终位于屏幕底部。 Scrollview 有一个垂直的 LinearLayout,它在循环内添加了视图。它工作得非常完美,除非 LinearLayout 中有足够的视图使其可滚动,最后一个元素总是被发送消息框覆盖。如果我使发送消息框不可见,您可以看到布局中的所有视图。看清楚图片。
我不想使用 ListView,因为我不想使用适配器
左边的这张图片显示了被覆盖的最后一个项目。然后使发送消息不可见显示最后一个元素。
这是布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_chat" tools:context="com.example.brian.cleverrent.ChatActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:id="@+id/scrollView" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/chatTimeLineLayout">
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sendMessageLayout"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#eeeeee"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chatEditText"
android:layout_weight=".9"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/chatSendButton"
android:layout_weight=".1"/>
</LinearLayout>
</RelativeLayout>
【问题讨论】: