【问题标题】:Android Title bar gets pushed up when edit text content increases编辑文本内容增加时,Android 标题栏会向上推
【发布时间】:2013-04-07 12:45:32
【问题描述】:

我有一个仅包含编辑文本视图的相对布局。但是当edittext的内容增加时,我的标题栏会向上移动。我经历的大多数解决方案都解决了键盘弹出时标题栏移动的问题。但是我没有发现任何内容以防其内容增加。我还使用了 android:isScrollContainer="false",正如这篇文章 How to avoid soft keyboard pushing up my layout? 中所建议的那样,但仍然是同样的问题。有没有办法防止它?这是我的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="false" 
    android:background="@drawable/background" >

    <EditText
        android:id="@+id/hidden_edit_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:imeOptions="flagNoExtractUi"
        android:inputType="textMultiLine"
        android:singleLine="false"
        android:paddingLeft="10sp"
        android:paddingTop="5sp"
        android:paddingRight="5sp"
        android:scrollbars="vertical"
        android:background="@android:color/transparent"
        android:textSize="26sp" >
    </EditText>
</RelativeLayout>

【问题讨论】:

    标签: android layout android-edittext titlebar


    【解决方案1】:

    我设法通过将edittext 放入滚动视图并在清单中将adjustPan 替换为adjustSize 来解决此问题。这是最终的工作布局

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/rl_view"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:background="@drawable/background">
    <EditText
        android:id="@+id/hidden_edit_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:imeOptions="flagNoExtractUi"
        android:inputType="textMultiLine"
        android:paddingLeft="10sp"
        android:paddingRight="5sp"
        android:paddingTop="5sp"
        android:singleLine="false"
        android:textSize="25sp" >
    </EditText>
    </ScrollView>
    

    【讨论】:

      【解决方案2】:

      删除后尝试运行您的代码:

      android:background="@android:color/transparent"
      

      【讨论】:

      • 还是一样,我看不出背景和布局变化之间有任何关系
      【解决方案3】:

      将您的相对布局高度和宽度设置为wrap_content.......... 可能有效。因为当文本增加你的完整布局时。试试看,请 rpy

      【讨论】:

        【解决方案4】:

        通常可以通过将android:windowSoftInputMode="adjustPan" 属性添加到 AndroidManifest 文件中的活动来解决此问题。

        【讨论】:

          猜你喜欢
          • 2012-07-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-07-05
          相关资源
          最近更新 更多