1

1 つの Android アクティビティには、その下にいくつかのボタンがあるいくつかの入力フィールドがあります。私はすべてをプッシュするソフトキーボードではなく、ユーザーが別の入力フィールドに簡単に移動できるようにしたいので、入力フィールドとボタンを ScrollView に入れました。

ここで、ソフトキーボードが閉じているときはボタンを画面の下部に配置し
、キーボードが開いているときは ScrollView の入力フィールドのすぐ下に配置したいと考えています。
追加すると

android:layout_below="@id/input_fields"

ボタンは常に入力フィールドの下にありますが、画面の下部にはありません。

android:layout_alignParentBottom="true"

それらを下に揃えますが、キーボードが開いているときは、最後の入力フィールドの前にあります。

何をすべきか知っている人はいますか?

私のレイアウトファイルの例:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


        <RelativeLayout
            android:id="@+id/input_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentTop="true" >

                   <!-- some input-fields -->

        </RelativeLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"

            android:layout_alignParentBottom="true"
            android:layout_below="@id/input_fields"

            android:padding="5dp">

            <!-- 2 buttons -->

        </LinearLayout>
</RelativeLayout>

さらに詳しい情報が必要な場合は、お問い合わせください。
事前に助けてくれてありがとう!

編集: いくつかの詳細情報:

「の前」とは、ボタンが入力フィールドを「隠し」ていたことを意味します。これは、入力フィールドのレイアウトではなく、親レイアウトの最後 ( ScrollView)。あなたの提案を使用すると、これはなくなりましたが、ボタンは常にキーボードの真上に表示されます(以前はそのようにしましたが、スペースを節約するために少し違う方法でやりたいと思います)。キーボードが開いているときに、入力フィールドの直後にその ScrollView にボタンを配置したいと思います。ScrollView だけが表示されるように、最後までスクロールすると、下部 (入力フィールドの後) にボタンが表示されます。それは問題にはなりません、ただし、ScrollView がすべてのスペースを埋めるかどうかに関係なく、キーボードを閉じたときにボタンを画面の下部にとどめたいと思います。何かアイデアがあればよろしくです!

4

1 に答える 1

-1

次のようにフィールドを追加しScrollView、ボタンを外側に配置しますScrollView

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

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <LinearLayout
        android:id="@+id/input_fields"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <!-- some input-fields -->

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp" >

    <!-- 2 buttons -->

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

</LinearLayout>

また使用

<activity android:windowSoftInputMode="adjustResize" . . . >

あなたの活動タグで。これを確認してくださいhttp://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

于 2013-01-31T18:04:20.520 に答える