Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 线性布局中的相对布局是否可以滚动查看?_Android_Android Layout_Scrollview_Android Linearlayout_Android Relativelayout - Fatal编程技术网

Android 线性布局中的相对布局是否可以滚动查看?

Android 线性布局中的相对布局是否可以滚动查看?,android,android-layout,scrollview,android-linearlayout,android-relativelayout,Android,Android Layout,Scrollview,Android Linearlayout,Android Relativelayout,在我的应用程序中,我有一个将国家输入数据库的布局。我希望我的布局是可滚动的,因为在某些设备上,键盘可能会阻止文本字段。我知道我可以使用ScrollView来做这件事,但我有一个问题。我的布局包括一个整体线性布局,但我在相对布局中包含了两个按钮。这给了我一种不寻常的滚动方式,即使我没有输入文本,整个屏幕似乎也会滚动,在屏幕底部留下一个很大的间隙。有什么想法吗 以下是我的布局: <?xml version="1.0" encoding="utf-8"?> <ScrollView

在我的应用程序中,我有一个将国家输入数据库的布局。我希望我的布局是可滚动的,因为在某些设备上,键盘可能会阻止文本字段。我知道我可以使用ScrollView来做这件事,但我有一个问题。我的布局包括一个整体线性布局,但我在相对布局中包含了两个按钮。这给了我一种不寻常的滚动方式,即使我没有输入文本,整个屏幕似乎也会滚动,在屏幕底部留下一个很大的间隙。有什么想法吗

以下是我的布局:

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

您的
线性布局
的高度设置为
填充父项
。将其更改为
wrap\u content
。您的
RelativeLayout
设置方式相同。也可能是罪魁祸首

<LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@drawable/map" 
        android:scrollbars = "vertical" >

您还可以将滚动视图放在另一个布局中。有一个垂直的线性布局,里面有两个布局,一个用于所有应该用layout_weight=“1”滚动的布局,另一个位于底部,由按钮组成

您的布局将类似于以下内容:

Vertical LinearLayout
    LinearLayout with layout_weight="1"
        ScrollView
            Layout containing your stuff
    layout containing buttons