2012-06-03 30 views
16

EditTextを含むPopupWindow(Android 2.2)を表示する簡単なテストプロジェクトを一緒にスローしました。私がEditTextをタップすると、ソフトキーボードが表示されます。しかし、ソフトキーボードはEditTextをカバーしているので、EditTextを表示するために画面をパンすることはできません。私のコード:ソフトキーボードがPopupWindowのEditTextをカバーしています

TestAdjustPanActivity.java:

package com.example; 

import android.app.Activity; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.widget.PopupWindow; 

public class TestAdjustPanActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     final PopupWindow pw = new PopupWindow(this); 
     pw.setContentView(getLayoutInflater().inflate(R.layout.popup, null, false)); 
     pw.setWidth(400); 
     pw.setHeight(600); 
     pw.setFocusable(true); 

     pw.setOutsideTouchable(true); 
     pw.setTouchable(true); 
     pw.setBackgroundDrawable(new BitmapDrawable()); 

     // This is the line referred to in the edit: 
     pw.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 

     findViewById(R.id.main).post(new Runnable() { 
      public void run() { 
      pw.showAtLocation(findViewById(R.id.main), Gravity.NO_GRAVITY, 0, 0); 
      } 
     }); 
    } 
} 

main.xml:

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

    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

</LinearLayout> 

popup.xml:

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#666666" 
     android:orientation="vertical" > 

     <EditText 
      android:id="@+id/current_password" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="40dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="300dp" /> 
    </LinearLayout> 

</ScrollView> 

...と私のAndroidManifest.xmlが含まれていませんアプリ内の唯一のアクティビティのタグの行android:windowSoftInputMode="stateUnspecified|adjustPan"

アイデア?この問題に関連するSOに関する他の投稿は、私のために行っていません。私が見逃しているのは、私がそれを期待している通りのパニングを避けているからです。

EDIT:私が持っているAndroid 3.2デバイスで画面が完全にパンする原因となったように、TestAdjustPanActivityの行を追加しようとしました。しかし、それはまだ私のAndroid 2.2デバイス上でパンしない、これはこれをさらに混乱させる。

答えて

4

、およびEditTextを表示したままにするためのパンニングは、ダイアログで2.2で正常に動作します。

0

あなたはもっと簡単な方法があります

android:windowSoftInputMode="stateHidden|adjustPan" 
+0

Meh、残念ながら運はありません。しかし、ありがとう! – Lewis

3

android:windowSoftInputMode="stateUnspecified|adjustPan 

を変更する必要があります。アクティブなキーボードの代わりのレイアウトを提供するだけです。

  1. 「Android tools/New Resource File ...」をクリックしてプロジェクトを選択します。
  2. レイアウトを選択すると、ファイル名が「メイン」になります(競合は心配しないでください)。
  3. [次へ]をクリックします。次に左のリストで「キーボード」を選択し、右に移動します(「 - >」をクリックします)。
  4. 右側にキーボードの状態を選択します。
  5. 終了をクリックします。
  6. "res/layout"にあるmain.xmlの内容をres/layout-keyssoftの新しいファイルにコピーしてください。
  7. キーボードがそうでないように新しいレイアウトを修正してください。これらの2つのレイアウト中の各成分のための「ID」S(ペーストが必要とされたコピー理由です)。
  8. それは

は、それがどのように動作するかを理解するのに約configuration changesを読むどのように機能するかをお楽しみください。なお、EVERY設定変更(オリエンテーション変更、言語変更など)によってアクティビティの再作成が発生します(そのような場合、onCreateの引数はnullではありません)。異なるために異なるレイアウトを提供できますケース。

+0

Androidのドキュメントによると、これはキーボードの実際の使用可能性が変更されたときにのみ機能し、残念ながら単に表示または非表示になったときには機能しません。しかし、彼らはConfigurationクラスのkeyboardHiddenプロパティについて言及していますが、これについては私が見ていきます。ありがとう! – Lewis

1

は、私は問題は、ScrollView

XMLに、あなたがcheck all different answers thereできる別の問題次のような存在となっていることを使用するのである疑い、そしてあなたのために働くことがあります。

1

変更この

android:windowSoftInputMode="stateUnspecified|adjustPan" 

のみマニフェストファイル内

android:windowSoftInputMode="adjustPan" 

に、私はちょうどダイアログの代わりに、PopupWindowを使用して終了し、将来的にこの時につまずく誰のための

関連する問題