soft-keyboardが表示されたときにUIコンポーネントのサイズを変更するコードを書こうとしました。 adjustResize,を使用すると、UIコンポーネントのサイズが変更され、同時にadjustPanも同じ出力をしました。 これらの違いと、それぞれのコンポーネントを使用するタイミングを教えてください。UIのサイズ変更にはどちら(adjustPanまたはadjustResize)が良いのでしょうか?
以下は私のxmlです:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<EditText
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:text="My Button" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
とmenifestファイルです:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adjustscroll"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.adjustscroll.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
アンドロイド開発者サイトリンク]1より
"adjustResize". >; アクティビティーのメインウィンドウは、画面上のソフトキーボードのスペースを確保するために、常にリサイズされます。 キーボードが表示されます。
>; アクティビティーのメインウィンドウは、ソフト>キーボードのためにサイズ変更されません。 gt;キーボードのスペースを確保するために、アクティビティのメインウィンドウのサイズが変更されることはありません。むしろ、ウィンドウの内容は自動的にパンされます。 現在のフォーカスがキーボードによって遮られることはありません。 そのため、現在のフォーカスがキーボードによって遮られることはなく、ユーザーは常に自分が入力しているものを見ることができます。これは一般的に、サイズ変更 なぜなら、ユーザーはソフトキーボードを閉じる必要があるからです。 を閉じる必要があるかもしれないからです。
コメントによると、アクティビティマニフェストで以下を使用してください。
<activity android:windowSoftInputMode="adjustResize"> </activity>
doc]1が言うように、正しい値の組み合わせにも留意してほしい:
設定値は、次の表に示す値のいずれかでなければならない、 または、1つの"state..."値と1つの"adjust..."値の組み合わせでなければなりません。 どちらのグループにも複数の値を設定する - 複数の "state..."値を設定する、 例えば、複数の "state..."値を設定しても、結果は未定義です。個々の値は 縦棒(|)で区切られます。例えば
<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >