Android 调节器第一次后无法正常工作

Android adjustpan not working after the first time(Android 调节器第一次后无法正常工作)

本文介绍了Android 调节器第一次后无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:从屏幕上第二次显示软键盘开始,它完全隐藏了我的 EditText.

My problem: starting from the second time the software keyboard is shown on the screen, it entirely hides my EditText.

属性android:windowSoftInputMode="adjustPan" 已在AndroidManifest.xml 中指定,但只在第一次生效.

Attribute android:windowSoftInputMode="adjustPan" has been specified in the AndroidManifest.xml, but it works only the first time.

我有以下布局:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="464dp"
        android:gravity="top"
        android:orientation="vertical"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="10"
            android:background="#E3E3E2"
            android:gravity="top" />

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

            <EditText
                android:id="@+id/addListText"
                android:layout_width="0dp"
                android:layout_height="48dp"
                android:layout_weight="10"
                android:contentDescription="@string/addItemContentDescription"
                android:gravity="bottom|center_horizontal"
                android:inputType="textLongMessage"
                android:textColor="#E3E3E2"
                android:visibility="gone" />

            <ImageButton
                android:id="@+id/addTextListButton"
                android:layout_width="0dp"
                android:layout_height="48dp"
                android:layout_weight="1"
                android:layout_gravity="right"
                android:background="@android:color/transparent"
                android:contentDescription="@string/addItemButton"
                android:scaleType="fitCenter"
                android:src="@drawable/plus_add"
                android:visibility="gone" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:gravity="bottom|center_horizontal"
        android:orientation="horizontal"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

        <ImageButton
            android:id="@+id/syncListsButton"
            android:layout_width="64dp"
            android:layout_height="match_parent"
            android:src="@android:drawable/ic_popup_sync" />

        <ImageButton
            android:id="@+id/showOrHide"
            android:layout_width="64dp"
            android:layout_height="match_parent" />

        <ImageButton
            android:id="@+id/delListButton"
            android:layout_width="64dp"
            android:layout_height="match_parent"
            android:src="@android:drawable/ic_menu_delete" />
    </LinearLayout>
</LinearLayout>

showOrHide"按钮显示/隐藏addListText"/addTextListButton"组合.

The "showOrHide" button shows/hides the "addListText"/"addTextListButton" combo.

当第一次显示 EditText 并且我触摸它时,屏幕上出现软键盘,并且addListText"/addTextListButton"组合被正确平移.当我隐藏键盘然后再次显示时,键盘完全覆盖了我的 addListText 编辑框!

When the EditText is shown for the first time and I touch it, the soft keyboard appears on the screen and the "addListText"/"addTextListButton" combo is panned correctly. When I hide the keyboard and then show it again, the keyboard covers completely my addListText editbox!

知道发生了什么吗?我正在 Android 4.2.2 上测试它.

Any idea on what's going on? I'm testing it on Android 4.2.2.

请帮忙!谢谢:-)

我也尝试将第一个 LinearLayout 放在 ScrollView 中,但它不起作用!

edit: I've also tried to put the first LinearLayout inside a ScrollView but it doesn't work!

推荐答案

继承 EditText 并重写 onKeyPreIme(int keyCode, KeyEvent event) 方法,如下所示:

subclassed EditText and overridden the method onKeyPreIme(int keyCode, KeyEvent event) like this:

   @Override
   public boolean onKeyPreIme(int keyCode, KeyEvent event)
   {
      if(keyCode == KeyEvent.KEYCODE_BACK)
        {
            clearFocus();
        }
   return super.onKeyPreIme(keyCode, event);
   }

现在当按下返回键时,EditText 失去了焦点.然后再次点击它,调整盘将起作用.

Now when the back key is pressed, the EditText lost the focus. Then tapping it again adjustpan will work.

这篇关于Android 调节器第一次后无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android 调节器第一次后无法正常工作

基础教程推荐