键盘出现时如何确保特定视图可见?

时间:2012-06-05 16:59:33

标签: android

我的布局顶部有一个图形,中间是EditText,下面是一个按钮,如下所示:

Example layout

当用户输入EditText时,我想平移布局,以便" Go"按钮仍然可见,即使这意味着从顶部剪切图像,如下所示:

Wanted layout

我知道清单中的windowSoftInputMode="adjustPan",但这并不起作用,因为它只有足够长的时间才能看到EditText。有没有办法确保平移直到按钮可见?


对于K_Anas的评论,这是我的布局。与第一个屏幕截图相比,它删除了所有额外的边距和间距,以消除任何其他问题来源。

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

    <View
        android:layout_width="300dp"
        android:layout_height="150dp"
        android:layout_alignParentTop="true"
        android:background="#999"/>

    <EditText
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:hint="Sample..."/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Go"/>

</RelativeLayout>

3 个答案:

答案 0 :(得分:2)

与Android开发人员的视频群聊,似乎没有一种简单的方法可以解决这个问题。共识似乎是重新设计布局而不是使用API​​来解决问题。

答案 1 :(得分:1)

你试过了吗?

android:windowSoftInputMode="adjustResize"

在你的活动标签中的标签

在Android开发者博客上查看这些docs

我尝试使用:android:windowSoftInputMode="stateVisible|adjustResize"

进行布局

并给我这些结果:

enter image description here enter image description here

答案 2 :(得分:0)

我确定这不是最好的方法,但你不能只更改按钮的布局属性(添加/更改边距)并在单击edittext时重绘吗?使用onClickListener&amp;也许你的按钮无效。

相关问题