[英]ScrollView and LinearLayout
我試圖在Android中獲得一個非常簡單的布局,但我無法讓它工作。 我想要的只是一個標題(通過include
一個XML文件),然后是ScrollView
以顯示大量文本,底部有兩個按鈕,它們應始終可見。
我已經擺弄了LinearLayout
和RelativeLayout
,但不知何故,我無法讓它發揮作用。 我到現在所擁有的是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/header" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/svDisclaimer"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvDisclaimer">
</TextView>
</ScrollView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/svDisclaimer"
>
.. [ snip ] ..
</LinearLayout>
</RelativeLayout>
</LinearLayout>
(.. [snip] ..是我的按鈕所在的位置)標題在那里,滾動視圖彈出,但按鈕無處可見。
您的ScrollView的高度設置為fill_parent
,它將ScrollView下方的所有內容從屏幕底部推出。 你將永遠不會看到你無法滾動的內容...嘗試這種模式:
<ScrollView >
<RelativeLayout >
<TextView />
<LinearLayout >
<!-- [ snip ] -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
您也可以使用RelativeLayout位置標記來刪除LinearLayout。 ( android:below
, android:toRightOf
等)
嘗試從我的評論中使用此配置:
<ScrollView
...
android:above="@+id/buttons" >
...
</ScrollView>
<LinearLayout
android:id="@+id/buttons"
android:layout_alignParentBottom="true"
... >
...
</LinearLayout>
就像Sam說的那樣,將ScrollView的高度設置為fill_parent會將按鈕從屏幕上移開。 但是,有一種方法可以使用RelativeLayout的布局標簽。 試試這個:
<LinearLayout>
[snip]
<RelativeLayout>
<!-- Declare the buttons *before* the ScrollView, but use layout params to move
them to the bottom of the screen -->
<LinearLayout
android:id="@+id/buttonParent"
android:layout_alignParentBottom="true">
[Buttons go here]
</LinearLayout>
<!-- The "android:layout_above" attribute forces the ScrollView to leave space for the buttons -->
<ScrollView
android:height="fill_parent"
android:layout_above="@id/buttonParent" />
[snip]
</ScrollView>
</RelativeLayout>
</LinearLayout>
另一種方法是將必須保留在屏幕上的頂部和底部元素放在framelayouts中。 http://android-er.blogspot.ca/2011/06/example-of-framelayout.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.