简体   繁体   English

Android ChatActivity底部LinearLayout覆盖ScrollView可滚动区域的底部

[英]Android ChatActivity Bottom LinearLayout covers bottom of ScrollView scrollable area

I'm making a chat Activity that has a send message box at the bottom. 我正在进行一个聊天活动,该活动的底部具有一个发送消息框。 The send message box should always be visible and always be at the bottom of the screen. 发送消息框应始终可见,并始终位于屏幕底部。 The Scrollview has a vertical LinearLayout that has views added to it inside of a loop. Scrollview有一个垂直的LinearLayout,在循环内添加了视图。 It works pretty much perfectly except when the there are enough views in the LinearLayout to make it scrollable the last element is always covered by the send message box. 除非在LinearLayout中有足够的视图使其可滚动时,否则它的效果非常好,最后一个元素始终由发送消息框覆盖。 If I make the send message box invisible you can see all of the views in the layout. 如果我使“发送消息”框不可见,则可以看到布局中的所有视图。 See images for clarity. 为清楚起见,请参阅图片。

I DO NOT WANT TO USE A ListView because I don't want to have to use an adapter 我不想使用ListView,因为我不想使用适配器

This image on the left shows the last item being covered. 左侧的这张图片显示了最后被覆盖的项目。 Then making the send message invisible shows the last element. 然后使发送消息不可见,将显示最后一个元素。

在此处输入图片说明 在此处输入图片说明

Here's the layout 这是布局

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

Maybe you could try using 也许您可以尝试使用

android:fillViewport="true"

for the ScrollView. 用于ScrollView。 Haven't tested it myself, but it was proposed as a solution to a similar problem here LinearLayout not expanding inside a ScrollView . 我自己还没有测试过,但是它被提议作为解决类似问题的一种解决方案,此处LinearLayout不在ScrollView内扩展

Solution was to add... 解决方案是添加...

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

Thanks to Nestel for answer 感谢Nestel的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM