WindowSoftInputMode and ScrollView

6
我的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>

为了确保在键盘弹出时,第一个RelativeLayout中定义的背景图像不会被压缩,我在活动的清单文件中设置了android:windowSoftInputMode="stateVisible|adjustPan"。现在背景和布局都没有问题,没有任何内容被调整大小。
但问题是我的ScrollView现在无法工作,因为我认为由于上述修改清单文件,系统认为窗口不需要调整大小,所以ScrollView未被激活。当我将android:windowSoftInputMode="stateVisible|adjustPan"移除时,滚动起作用,但当键盘弹出时,背景被压缩。
有没有办法编写代码,使我的背景不被压缩,而我的ScrollView仍然可以工作?谢谢!
2个回答

3

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

android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

我不知道是否有必要,但您可以尝试将ScrollView标签的fillViewPort设置为true。 因此,它应该看起来像我向您展示的内容:

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

请告诉我你的进展情况。


3
谢谢,但无济于事。本质上,我想让adjustResize适用于ScrollView,而让adjustPan适用于承载背景的RelativeLayout。 - capcom
我遇到了这个问题。希望你们已经找到了解决方案 :/ - Rawr

1
在你的scrollview中放置一个相对布局,子项0是一个imageview,子项1是你的内容。使用imageview作为你的背景图片(src),而不是scrollview的背景。imageview将尊重scaleTypes,而布局的背景不会。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接