0

我有一个用于在我的应用程序中将国家/地区输入数据库的布局。我希望我的布局是可滚动的,因为在某些设备上,键盘最终会阻止文本字段。我知道我可以使用 ScrollView 来执行此操作,但我遇到了问题。我的布局由一个整体 LinearLayout 组成,但我在 RelativeLayout 中包含了 2 个按钮。这给了我一种不寻常的滚动方法,即使我没有输入文本,整个屏幕似乎也会滚动,在屏幕底部留下很大的空隙。对此有什么想法吗?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@drawable/map" 
        android:scrollbars = "vertical" >

        <!-- Enter country -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/editcountry"
            android:textColor="@color/black"
            android:textSize="22sp" />

        <AutoCompleteTextView 
            android:id="@+id/editcountry"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:hint="@string/hintprompt"
            android:imeOptions="actionDone" />

        <!-- Enter year -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/edityear"
            android:textColor="@color/black"
            android:textSize="22sp" />

        <Spinner
            android:id="@+id/yearspin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

        <!-- Enter month -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/editmonth"
            android:textColor="@color/black"
            android:textSize="22sp" />

        <Spinner
            android:id="@+id/monthspin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:entries="@array/months" />

        <!-- Enter mode of transport -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/edittransport"
            android:textColor="@color/black"
            android:textSize="22sp" />

        <Spinner
            android:id="@+id/transportspin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:entries="@array/transport" />

        <!-- Enter description -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/editdesc"
            android:textColor="@color/black"
            android:textSize="22sp" />

        <EditText
            android:id="@+id/editdesc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hintprompt"
            android:inputType="text" 
            android:imeOptions="actionDone"/>

            <!-- Place buttons at the bottom of the screen -->
            <RelativeLayout 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <Button
                    android:id="@+id/backmain"
                    android:layout_width="150dp"
                    android:layout_height="50dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:text="@string/back" />

                <Button
                    android:id="@+id/add"
                    android:layout_width="150dp"
                    android:layout_height="50dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:text="@string/addinfo" />

            </RelativeLayout>
    </LinearLayout>
</ScrollView>
4

2 回答 2

0

LinearLayout的高度设置为fill_parent. 将其更改为wrap_content. 您RelativeLayout的设置方式相同。也可能是罪魁祸首。

<LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@drawable/map" 
        android:scrollbars = "vertical" >
于 2013-04-13T13:02:50.333 回答
0

您还可以将您的滚动视图放在另一个布局中。有一个垂直的 LinearLayout,里面有两个布局,一个用于您应该使用 layout_weight="1" 滚动的所有内容,在底部另一个布局包含您的按钮

您的布局将与此类似:

Vertical LinearLayout
    LinearLayout with layout_weight="1"
        ScrollView
            Layout containing your stuff
    layout containing buttons
于 2013-04-13T13:13:53.473 回答