【问题标题】:How to make ListView view auto scroll on top if EditText Grow如果 EditText 增长,如何使 ListView 视图在顶部自动滚动
【发布时间】:2021-12-31 18:56:06
【问题描述】:

这是我的问题。如果我在 EditText 中有很多文本,我有 EditText 和 ListView。 ListView 不会在顶部滚动,因此结果是 ListView 现在被 editText 占用。

This is the image when there is now text in EditText

This is the image when there is now many texts in EditText

我希望有人理解并帮助我解决另一个问题????????

这是我的代码:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <Button
        android:paddingTop="18dp"
        android:paddingBottom="18dp"
        android:text="send"
        android:id="@+id/button_send"
        android:layout_width="60dp"
        android:layout_height="52dp"
        android:layout_gravity="bottom|right"/>
<EditText
    android:id="@+id/mainEditText"
    android:background="#EBEBEB"
    android:hint="Type your message here..."
    android:layout_gravity="bottom"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textMultiLine|textCapSentences"
    android:maxLines="8"
    android:minHeight="48dp"
    android:minLines="1"
    android:paddingLeft="10dp"
    android:smoothScrollbar="true"
    android:scrollbars="vertical"
    android:scrollHorizontally="false"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="60dp"/>


    
    <RelativeLayout
        android:paddingBottom="50dp"
        android:layout_gravity="top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ListView
            android:layout_alignParentBottom="true"
            android:id="@+id/messages_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:listSelector="@android:color/transparent"
            android:stackFromBottom="true"
            android:transcriptMode="normal"></ListView>
        
        
    </RelativeLayout>
    

【问题讨论】:

  • 等等,我看不到我在这里发布的图片....希望你们能看到???????
  • 为此添加完整的布局代码。看来您的 editext 和 recyclerview 重叠
  • 兄弟看看我的完整布局代码我现在已经编辑了它。我不使用 recycleview 我使用 listView

标签: android listview scroll android-edittext


【解决方案1】:

用我的代码替换您的代码并尝试。你会得到你预期的结果

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="vertical">

    <ListView
        android:id="@+id/messages_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/mainEditText"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:listSelector="@android:color/transparent"
        android:stackFromBottom="true"
        android:transcriptMode="normal" />

    <EditText
        android:id="@+id/mainEditText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        android:layout_toStartOf="@+id/button_send"
        android:background="#EBEBEB"
        android:ems="10"
        android:hint="Type your message here..."
        android:inputType="textMultiLine|textCapSentences"
        android:maxLines="8"
        android:minHeight="48dp"
        android:minLines="1"
        android:paddingLeft="10dp"
        android:scrollbars="vertical"
        android:scrollHorizontally="false"
        android:smoothScrollbar="true" />

    <Button
        android:id="@+id/button_send"
        android:layout_width="wrap_content"
        android:layout_height="52dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom|right"
        android:text="send" />

</RelativeLayout>

【讨论】:

  • 我无法打开它兄弟我认为布局错误......兄弟帮我解决这个问题。我遇到了这个问题,我也是一个初学者
  • 什么打不开?
  • 我提供给你运行代码的代码。我自己测试过
猜你喜欢
  • 2017-09-14
  • 1970-01-01
  • 2020-04-22
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 2020-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多