LoginSignup
25
23

More than 5 years have passed since last update.

Androidアプリでキーボードの上までスクロールできるようにする

Last updated at Posted at 2014-09-18

AndroidアプリでScrollViewを表示中にキーボードを表示すると、一番上までスクロールしても画面の下の部分がキーボードに隠れてしまいます。
これを、キーボードを表示したままでも画面最下部までスクロールできるようにするには、以下のようにします。

1. ManifestにwindowSoftInputModeを設定する

AndroidManifest.xmlのactivityタグにandroid:windowSoftInputMode="adjustResize"を追加します。
これによって、キーボードが表示されたらアクティビティのサイズがキーボード分小さくなるようになります。

AndroidManifest.xml
<manifest
    ... >
    <application
        ... >

        <activity
            android:name="hoge.MyActivity"
            ...
            android:windowSoftInputMode="adjustResize" >
        </activity>

    </application>
</manifest>

2. ScrollViewのweightを1にする

ScrollViewweight1にします。
これにより、アクティビティがリサイズされてもScrollViewが画面いっぱいに広がるようになります。

myactivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        ...

    </ScrollView>

</RelativeLayout>

 
こちらを参考にしました。

25
23
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
23