[英]Relative layout within Linear layout is scrollview possible?
我有一個布局,可以在我的應用程序中將國家/地區輸入數據庫。 我希望布局可以滾動,因為在某些設備上,鍵盤最終可能會阻塞文本字段。 我知道我可以使用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>
您的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" >
您也可以將您的scrollView放在另一個布局中。 有一個垂直的LinearLayout,里面有兩個布局,一個用於您應以layout_weight =“ 1”滾動的所有內容,而在底部則是由按鈕組成的另一個布局
您的布局將類似於以下內容:
Vertical LinearLayout
LinearLayout with layout_weight="1"
ScrollView
Layout containing your stuff
layout containing buttons
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.