WindowSoftInputMode和ScrollView

cap*_*com 6 android android-layout

我的Android应用程序的主要活动如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:orientation="vertical"
        android:paddingLeft="60dp"
        android:paddingTop="53dp" >

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/RelativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/billAmountText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/billAmount_string"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/billAmount"
                android:layout_width="173dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/billAmountText"
                android:layout_marginTop="3dp"
                android:inputType="numberDecimal" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

为了确保键盘弹出时背景图像(在第一个RelativeLayout中定义)不会被挤压,我已android:windowSoftInputMode="stateVisible|adjustPan在清单文件中设置了我的活动.现在所有的背景和布局都很好,没有任何调整大小.

但问题是我的ScrollView现在不能正常工作,因为我认为由于我对清单的上述修改,系统认为窗口不需要调整大小 - 所以ScrollView没有被激活.当我android:windowSoftInputMode="stateVisible|adjustPan拿出滚动工作时会发生相反的情况,但是当键盘弹出时背景会被挤压.

有没有办法对它进行编码,这样我的背景就不会受到挤压,我的ScrollView仍然有效?谢谢!

yug*_*oid 3

尝试在您的活动中使用windowSoftInputMode具有以下值的属性:

android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

我不知道是否有必要,但您可以尝试将to添加到布局的ScrollView标签中。所以它应该看起来像我在下面向您展示的内容:fillViewPorttrue

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

        <!-- Other Views -->
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

让我知道你的进展。

  • 谢谢,但没有运气。本质上,我希望将 adjustmentResize 应用于 Scrollview,但我希望将 adjustmentPan 应用于承载背景的relativelayout。 (3认同)