以下のように、ソフトキーボードがアクティブになったときにレイアウトを調整/サイズ変更したいと思います。
前後:
SO でいくつかのリソースが見つかりました:
- ソフトキーボードが表示されている間、すべてのフィールドとテキストを表示したままにする方法
- Androidのソフトキーボードが表示されるとレイアウトが台無しになる
- ソフトキーボードがオンのときにレイアウトを調整する
しかし、質問と回答はかなり曖昧なので、私が何を望んでいるのかをより明確にした質問を以下に示します。
要件:
- あらゆる画面サイズの携帯電話で動作するはずです。
- 「FACEBOOK」と「Facebook にサインアップ」の余白/パディングスペースが変更前と変更後で変化していることに気付きました。
- スクロールビューは関係ありません。
ベストアンサー1
追加するだけ
android:windowSoftInputMode="adjustResize"
AndroidManifest.xml でこの特定のアクティビティを宣言すると、レイアウトのサイズ変更オプションが調整されます。
レイアウト設計のためのソースコードを以下に示します。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="FaceBook"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="username" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="password" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="20dp"
android:text="Log In" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="17dp"
android:gravity="center"
android:text="Sign up for facebook"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>