【问题标题】:Android: When the keyboard pops up, the layout is invisible. How do I solve this?Android:当键盘弹出时,布局是不可见的。我该如何解决这个问题?
【发布时间】:2009-12-17 23:57:08
【问题描述】:

在我的布局中,屏幕底部有一个TextView。问题是,当我在文本框内单击以键入内容时,键盘会覆盖文本框,因此我无法看到正在发生的事情......有什么解决方案吗?这是我的布局...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/layout_bg">

    <ImageView
        android:id="@+id/headerimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingLeft="5dp"
        android:src="@drawable/header_image" />

    <LinearLayout 
        android:id="@+id/secondaryLayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="320dip"
        android:layout_marginTop = "5dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip"
        android:cacheColorHint="#00000000">

        <!-- A ListView appears here -->

    </LinearLayout>

    <RelativeLayout 
        android:id="@+id/message"
        android:orientation="horizontal"
        android:layout_width="300dip"
        android:layout_height="80dip"
        android:layout_gravity="center">

        <EditText
            android:id="@+id/MessageText"
            android:layout_height="wrap_content"
            android:layout_width="230dip"
            android:layout_marginLeft="8dip"
            android:layout_marginTop = "8dip"
            android:paddingBottom = "8dip"
            android:paddingLeft="15px"
            android:hint="Type something here...">
        </EditText>
        <Button
            android:id="@+id/MsgButton"
            android:layout_margin="0dip"
            android:layout_width="48dip"
            android:layout_toRightOf="@id/MessageText"
            android:layout_height="48dip">
        </Button>

    </RelativeLayout>       
</LinearLayout>

【问题讨论】:

  • 嘿,你有没有找到解决同样问题的方法。如果你有帮助,请帮忙?

标签: android layout overlap


【解决方案1】:

您应该能够在清单文件中控制它,方法是向活动元素添加 android:windowSoftInputMode="adjustPan" 属性。请参阅 windowSoftInputMode documentationblog post 更详细地解释这一点。

【讨论】:

  • 这看起来是正确的方法。当我遇到同样的问题时,我尝试了其他方法。我将整个布局放在滚动视图中。因此,当软键盘可见时,滚动条会自行调整,从而使最底部的小部件可见。这可能是一个粗略的黑客攻击,它在 FWIW 上奏效了。
猜你喜欢
  • 2018-04-15
  • 1970-01-01
  • 2020-03-25
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多