16

私はいくつかのフィールド(名前、電子メール、パスワード、登録ボタン)を持つビューを持っています:

<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>

エディットテキストフィールドにフォーカスを合わせると、キーボードが表示され、ビューの下のフィールドに重なっています。そのため、キーボードが存在するときはそれらを見ることができません。下のフィールドが見えるようにビューをスクロール可能にする方法を知りたいのですが。さらに、フォーカスされたフィールドを表示するためにビューを自動的にスクロールさせる方法。

4

4 に答える 4

44

AndroidManifest.xmlファイルにアクティビティの属性を含める必要がありandroid:windowSoftInputMode="adjustResize"ます。そうすると、Androidが自動的にサイズ変更を行います。

<activity android:name="..."
          ...
          android:windowSoftInputMode="adjustResize">
    ...
/>
于 2012-05-15T11:11:35.077 に答える
7

簡単な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>
于 2012-05-15T12:13:48.090 に答える
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>
于 2012-05-15T11:14:24.653 に答える
0

私の場合、@AleksGソリューションは機能していませんでした。だから私は私の問題を解決しました

<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>
于 2016-07-05T18:54:31.570 に答える