2013-02-19 71 views
0

我試圖建立具有滾動型,其中的圖像(遠程URL)填滿屏幕(具有marginTop,marginLeft,marginRight和marginBottom設置爲圍繞5DP)Android應用當你向下滾動時,你會發現更多的UI組件。量表遠程圖像設備的高度和寬度

我發現很難將圖像縮放到精確的尺寸。沒有控制圖像的大小。有些可能很小,有些可能很大。如果它很小,我想伸展它以適應屏幕。我的XML看起來是這樣的:

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <ProgressBar 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:indeterminate="true" 
    android:layout_centerInParent="true" 
    android:visibility="invisible" 
    android:id="@+id/movieImageLoading"/> 

    <ImageView android:id="@+id/headerImage" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:scaleType="fitXY" 
    android:layout_marginTop="5dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginBottom="5dp" 
    android:contentDescription="@string/movie_image"></ImageView> 

    <Button 
     android:id="@+id/save2" 
     android:layout_width="150dp" 
     android:layout_marginTop="10dp" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/headerImage" 
     android:text="save" /> 

</RelativeLayout> 

這是不對的,有人可以幫我嗎?

謝謝。

+0

說「這是錯誤的」沒有幫助。怎麼了?你看到的行爲是什麼?理想情況下,張貼發生了什麼的屏幕截圖,以及你想如何看的樣機 – 2013-02-19 11:31:53

+0

嗨馬特。在下面的Pratik答案中指定了行爲。 屏幕截圖: http://postimage.org/image/wthseojsf/ http://postimage.org/image/is2rtogah/ – sharath 2013-02-19 11:48:07

+0

我現在還沒有試過,但不應該''centerInside'是所需的scaletype ?從文檔看來,它完全符合你的要求。編輯:見http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – Thrakbad 2013-02-19 13:16:50

回答

0

嘗試這種佈局

讓你的按鈕,底部固定,並設置與填充母按鈕上方的圖像視圖和最後一個指定進度條

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > <!-- here make wrap to fill --> 
    <Button 
     android:id="@+id/save2" 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:text="save" 
     android:layout_alignParentBottom="true" /> 

    <ImageView 
     android:id="@+id/headerImage" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/save2" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     android:contentDescription="movie_image" 
     android:scaleType="fitXY" > 
    </ImageView> 

    <ProgressBar 
     android:id="@+id/movieImageLoading" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_centerInParent="true" 
     android:indeterminate="true" 
     android:visibility="invisible" /> 
</RelativeLayout> 
+0

感謝您的回答PRATIK我仍然看到相同的行爲壽。 ,較小的圖像看起來像是按比例縮放X和Y,但不會伸展到底部,較大的圖像似乎超出了屏幕的底部 – sharath 2013-02-19 11:47:10

+0

屏幕截圖: http://postimage.org/image/wthseojsf/ http://postimage.org/image/is2rtogah/ – sharath 2013-02-19 11:52:31

+0

您好我已經更新了我的小改答案,請檢查一下。你必須RelativeLayout的高度FILL_PARENT代替WRAP_CONTENT – Pratik 2013-02-19 13:11:00