17

EditTextを含むPopupWindowを表示する簡単なテストプロジェクトをまとめました(Android 2.2の場合)。EditTextをタップすると、予想どおりソフトキーボードが表示されます。ただし、ソフトキーボードはEditTextをカバーしているため、画面をパンして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>

android:windowSoftInputMode="stateUnspecified|adjustPan"...そして私のAndroidManifest.xmlには、アプリ内の唯一のアクティビティのタグにその行が含まれています。

何か案は?この問題に関連するSOに関する他の投稿はどれも私のためにそれをしていません。ビューが期待どおりにパンされないようにするために、何が欠けていますか?

編集:示されているようにTestAdjustPanActivityに行を追加しようとしました。これにより、使用しているAndroid3.2デバイスで画面が完全にパンしました。ただし、Android 2.2デバイスではまだパンしないため、これはさらに混乱を招きます。

4

6 に答える 6

4

将来これに遭遇した人のために、私はPopupWindowの代わりにDialogを使用することになり、EditTextを表示したままにするためのパンはDialogを使用した2.2で正常に機能します。

于 2012-07-30T20:56:55.953 に答える
3

もっと簡単な方法があります。アクティブなキーボードの代替レイアウトを提供するだけです。

  1. プロジェクトを左クリックして、「Androidツール/新しいリソースファイル...」を選択します。
  2. レイアウトを選択し、ファイル名に「main」を付けます(競合について心配する必要はありません)。
  3. 「次へ」をクリックします。次に、左側のリストで[キーボード]を選択して右に移動します([->]をクリックします)。
  4. 右側でキーボードの状態を選択します。
  5. [完了]をクリックします。
  6. 次に、「res/layout」にあるmain.xmlのコンテンツを「res/layout-keyssoft」の新しいファイルにコピーします。
  7. キーボードがそのようにならないように、新しいレイアウトを修正します。これらの2つのレイアウトでは、それぞれのコンポーネントに同じ「ID」を維持することを忘れないでください(そのため、コピーペーストが必要でした)。
  8. それがどのように機能するかをお楽しみください

構成の変更について読んで、それがどのように機能するかを理解してください。構成を変更するたびに(方向の変更、言語の変更など)、アクティビティが再作成されるため(onCreateの引数がnullでない場合)、ケースごとに異なるレイアウトを提供できることに注意してください。

于 2012-06-04T21:16:45.943 に答える
2

問題は、でそれを使用しているためではないかと思いScrollViewますXML

これに似た別の問題がありました。そこですべての異なる回答を確認でき、うまくいく可能性があります。

于 2012-06-07T05:30:03.630 に答える
1

これを変える

android:windowSoftInputMode="stateUnspecified|adjustPan"

android:windowSoftInputMode="adjustPan"

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

于 2012-06-07T09:06:28.663 に答える
0

変更する必要があります

android:windowSoftInputMode="stateUnspecified|adjustPan 

android:windowSoftInputMode="stateHidden|adjustPan"
于 2012-06-03T08:03:49.690 に答える
0

理解するのに数時間かかり、scrollviewを使用することになりました。

どうやら、ポップアップウィンドウとソフト入力キーパッドを使用してビューを非表示にすると、この問題を解決する方法はありません。スクロールビューに移動します。

于 2019-06-14T10:14:00.307 に答える