【问题标题】:TextView moves when entering text in EditText在 EditText 中输入文本时 TextView 移动
【发布时间】:2014-11-21 19:24:43
【问题描述】:

我正在开发一个简单的 HelloWorld 应用程序来获取信息。该应用程序有一个 TextView 的简单嵌套线性布局,它填充了 EditText 和发送按钮上的大部分布局。每当输入文本并单击“发送”时,它会将文本作为新行添加到 TextView。到目前为止,其他一切都很好,但是每当弹出键盘开始输入文本时,上面的 TextView 也会被向上推。我希望 TextView 保持原位,并在布局中调整大小。

图片1:https://flic.kr/p/pRHo4j 图二:https://flic.kr/p/pRQg7i

谢谢, 疯了

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView android:id="@+id/display_message"
              android:layout_weight="1"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:freezesText="true" />

    <LinearLayout android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText android:id="@+id/edit_message"
                  android:layout_weight="1"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:hint="@string/edit_message" />

        <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/button_send"
                android:onClick="sendMessage" />
    </LinearLayout>

</LinearLayout>

【问题讨论】:

    标签: android xml layout


    【解决方案1】:

    在 Android Manifest 的 Activity 标签中添加以下属性

    <activity
    ...
    android:windowSoftInputMode="adjustResize"
    />
    

    【讨论】:

      【解决方案2】:

      我以前也遇到过这个问题。有趣的是,我也在使用 LinearLayout。 如果您想控制事物的移动,请尝试使用相对布局。(或让它们保持不动)

      【讨论】:

        猜你喜欢
        • 2020-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-21
        • 2021-12-22
        • 1970-01-01
        相关资源
        最近更新 更多