我有一個在我的應用程序中輸入國家到數據庫的佈局。我希望我的佈局能夠滾動,因爲在某些設備上,鍵盤最終會阻止文本字段。我知道我可以使用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>