2

这是对这个问题的跟进。

在这个问题上花了几天时间,似乎无法得到我想要的。我需要非常简单的是,当键盘在触摸编辑文本字段后弹出时,整个视图可以滚动:

在此处输入图像描述

请注意,此视图不可滚动,也不必如此。

所以当用户点击edittext字段(比如第一个)时,它看起来像这样:

在此处输入图像描述

如果他/她选择,可以滚动视图以不再以它在此处的样子结束:

在此处输入图像描述

我已经尝试了所有我能想到的滚动视图组合,但它所做的只是拉伸我的背景图像。我确信有一个简单的解决方案,但我就是找不到。我真的很感谢任何可以解决这个问题的人。顺便说一下,这是布局的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background"
    android:orientation="vertical"
    android:paddingLeft="60dp"
    android:paddingTop="53dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="173dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView1"
        android:layout_marginTop="3dp"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/editText1"
        android:layout_marginTop="3dp"
        android:text="text2"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="173dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView2"
        android:layout_marginTop="3dp"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/editText2"
        android:layout_marginTop="3dp"
        android:text="text3"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="173dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView3"
        android:layout_marginTop="3dp"
        android:inputType="numberDecimal" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/editText3"
        android:layout_marginTop="3dp"
        android:text="text4" />

    <ImageView
        android:id="@+id/gearImage3"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@id/button1"
        android:layout_marginTop="70dp"
        android:clickable="true"
        android:contentDescription="@string/gearDescription_string"
        android:src="@drawable/gear" />

</RelativeLayout>

请注意,后两张图片不是来自真实的应用程序(photoshoped 以显示我需要的东西),但第一张来自我的应用程序。谢谢。

4

1 回答 1

5

ScrollView 只滚动到有数据的地方。因此,只需添加一个 ScrollView 就可以解决您的问题。将此添加到 xml 的开头:

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

然后显然将其添加到底部,在其他所有内容之后:

 </ScrollView>

我在我的应用程序中使用它,当键盘显示时,我仍然可以滚动到页面底部。如果屏幕截图 1 中显示的字段不超过一个普通电话页面,则无论如何它都不会滚动。它只会在您打开键盘时滚动,因为它无法看到整个屏幕。

希望这可以帮助!

于 2012-07-30T21:45:53.343 回答