2012-02-18 56 views
1
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF" > 

    <LinearLayout 
     android:layout_width="590dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:orientation="vertical" > 
... 

我可以將圖像作爲背景放在底部Activity(窗口)中嗎?例如,當滾動ScrollView時,圖像必須始終爲底部且可見。設置ImageView下方的ScrollView

回答

1

您是否嘗試過使用RelativeLayouts?喜歡的東西:

<RelativeLayout android:width="fill_parent" 
android:height="fill_parent" 
...> 

    <WhateverYouWantAtBottom android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    /> 

    <ScrollView android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <whateverYouWantScrollable android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 
    </ScrollView> 

</RelativeLayout> 

在底部,你可以有你想要的圖像的ImageView的。無論滾動視圖中的內容多長時間,只要將alignParentBottom設置爲true,imageview就不會從底部移出。

編輯:在上面的代碼中,<whateverYouWantAtTheBottom>將在我首先聲明它的背景中。前景將是scrollView的內容,就像在XML中最後添加的那樣。

+0

不錯,但在上面這個圖片。這可以在下面,例如,ScrollView? – 2012-02-18 22:52:21

+1

很簡單。無論您在後臺需要什麼,首先在您的XML代碼中聲明。例如,如果您希望scrollview位於ImageView上方,請首先編寫您的ImageView代碼,然後再編寫您的ScrollView代碼。我在答案中補充說。 – Urban 2012-02-19 10:07:32

0

我想這和它的工作對我來說

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

    <ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_launcher" 
    android:layout_alignParentBottom="true" 
    /> 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@id/imageView1" > 



    </ScrollView> 



    </RelativeLayout> 
+0

但這種方式如果你的滾動視圖已滿,即使它不會重疊你的imageview。這樣圖像將始終佔據屏幕的底部。問題要求圖片在背景中,而不是作爲底部的單獨部分。 – Urban 2012-02-18 22:35:56

+0

多數民衆贊成正是他想要的:) – confucius 2012-02-18 22:37:32

+0

我想他想要在背景圖像... – Urban 2012-02-18 22:39:00