当android软输入让你推高时,我怎样才能使视图在下方可见?

时间:2015-06-17 04:23:06

标签: android xml android-layout android-edittext window-soft-input-mode

我有一个edittext和一个位于布局中editext下方的按钮。

layout xml可能是这样的:

#include <iostream>

class Foo
{
public:
    int m_a;
    Foo(int i) : m_a(i) {}
};

inline static bool operator==(const Foo& l, const Foo& r)
{
    return  l.m_a == r.m_a;
}

static void coutResult(const Foo& l, const Foo&r)
{
    std::cout   << "l.m_a == " << l.m_a << ", "
            << "r.m_a == " << r.m_a << ", "
            << (l == r ? "true" : "false") << std::endl;
}

class Bar :
    public Foo
{
public:
    int m_b;
    Bar(int i, int j) : Foo(i), m_b(j) {}
};

inline static bool operator==(const Bar& l, const Bar& r)
{
    return  ((Foo)l) == ((Foo)r) &&
        l.m_b == r.m_b;
}

static void coutResult(const Bar& l, const Bar& r)
{
    std::cout   << "l.m_a == " << l.m_a << ", "
            << "l.m_b == " << l.m_b << ", "
            << "r.m_a == " << r.m_a << ", "
            << "r.m_b == " << r.m_b << ", "
            << (l == r ? "true" : "false") << std::endl;
}

int main(int argc, char** argv) {
    Foo a(1);
    Foo b(1);
    Foo c(2);

    coutResult(a, b);
    coutResult(a, c);
    coutResult(a, c);

    Bar d(1, 2);
    Bar e(1, 2);
    Bar f(1, 3);
    Bar g(2, 2);

    coutResult(d, e);
    coutResult(d, f);
    coutResult(d, g);
    coutResult(e, f);
    coutResult(f, g);
    coutResult(f, g);

    return 0;
}

androidmanifast中的布局活动是:

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

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="110dp"
        android:ems="10" >

    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="91dp"
        android:text="Button" />

</RelativeLayout>

所以,问题是:

当我点击或关注edittext时,软输入将自动向上推,它只是阻止/覆盖我的按钮,我想让按钮可见。当输入到来时,如何将按钮向上设置为软输入键。

有人可以给我一些建议吗?感谢。

2 个答案:

答案 0 :(得分:0)

尝试这个来维护它

android:windowSoftInputMode="adjustPan|stateAlwaysHidden"

答案 1 :(得分:-1)

将EditText和Button包装在ScrollView中,如下所示

<ScrollView>
  <LinearLayout android:orientation="vertical">
    <EditText/>
    <Button/>
  </LinearLayout>
</ScrollView>