13

私はいくつかのフィールド(名前、電子メール、パスワード、ボタンを登録する)との見解を持っている:私はのEditTextフィールドを集中するとキーボードが表示されたらアンドロイドビューをスクロール可能にする方法はありますか?

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ViewFlipper 
     android:id="@+id/viewflipper" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     //Layouts 

    </ViewFlipper> 

</ScrollView> 

、キーボードが表示され、ビューの下のフィールドを重ねています。だから、キーボードがあるときに私はそれらを見ることができない。私は下のフィールドを見ることができるようにビューをスクロール可能にする方法を知りたいです。さらに、ビューを自動的にスクロールさせてフォーカスされたフィールドを表示させる方法。

答えて

37

あなたはAndroidManifest.xmlファイルにあなたの活動のためのandroid:windowSoftInputMode="adjustResize"属性を含める必要が - して、Androidは自動的にサイズ変更を行う必要があります。

<activity android:name="..." 
      ... 
      android:windowSoftInputMode="adjustResize"> 
    ... 
/> 
+1

実際には "adjustPan | adjustResize"に設定されています。 adjustPanを削除すると動作しました。ありがとう! – Alexis

0

は、あなたはこれを試してみました:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<ViewFlipper 
    android:id="@+id/viewflipper" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/scroll_container"> 
     //Layouts 
    </ScrollView> 


</ViewFlipper> 

6

私は単純なXMLファイルを作成しました。これがあなたが探しているものであることを願っています。

ステップ1。キーパッドが現れたらスクロールすることができます。

ステップ2。テキストフィールドをクリックするとフォーカス/キーパッド上に表示されます。

<ScrollView android:id="@+id/ScrollView01" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillViewport="true" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:weightSum="1.0" 
    android:layout_height="match_parent" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:id="@+id/l_layout"> 
    <EditText 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/editText1" 
     android:layout_marginTop="100dp"> 
     <requestFocus></requestFocus> 
    </EditText> 
    <EditText 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/editText2" 
     android:layout_marginTop="100dp"> 
     </EditText> 
    </LinearLayout> 
</ScrollView> 
+0

私はスクロールビューに問題があり、fillViewportは必要なものです。 – AlexBrand

0

私のケースでは、@Aleks Gソリューションは機能しませんでした。私は問題を解決しました

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/registration_scroll_view" 
    android:layout_alignParentTop="true" 
    android:layout_above="@+id/btn_register_submit" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <!--This comment will be replaced 
      by your focusable views--> 

    </LinearLayout> 
</ScrollView> 

<Button 
    android:id="@+id/btn_register_submit" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/form_action_button_green" 
    android:gravity="center" 
    android:text="@string/submit" 
    /> 

</RelativeLayout> 
関連する問題