2016-04-28 106 views
0

我正在进行一个聊天活动,其底部有一个发送消息框。发送消息框应始终可见并始终位于屏幕的底部。 Scrollview有一个垂直的LinearLayout,在一个循环内部添加了视图。除非LinearLayout中有足够的视图使其可滚动,否则最后一个元素总是由发送消息框覆盖,它的工作原理非常完美。如果我使发送消息框不可见,则可以看到布局中的所有视图。为清晰起见请参阅图像Android ChatActivity底部LinearLayout覆盖ScrollView可滚动区域的底部

我不想使用的ListView,因为我不想有使用适配器

此图片左边显示覆盖的最后一个项目。然后使发送消息不可见显示最后一个元素。

enter image description hereenter image description here

这里的布局

<?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> 

回答

1

的解决办法是添加...

android:fillViewport="true" 
android:paddingBottom="50dp" 

感谢Nestel的答案