2013-02-19 70 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