【问题标题】:Android ChatActivity Bottom LinearLayout covers bottom of ScrollView scrollable areaAndroid ChatActivity Bottom LinearLayout 覆盖ScrollView 可滚动区域的底部
【发布时间】: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>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    也许你可以尝试使用

    android:fillViewport="true"
    

    对于滚动视图。自己还没有测试过,但是这里提出了它作为类似问题的解决方案LinearLayout not expanding inside a ScrollView

    【讨论】:

    • 结合使用您的答案并在滚动视图底部添加填充解决了问题
    【解决方案2】:

    解决方案是添加...

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

    感谢雀巢的解答

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多