2016-09-16 79 views
0

我试图显示从外部卡加载到占据整个屏幕的图像视图的位图。我的目标是显示它在Gallery应用中的显示方式。我在版面xml中尝试使用scaletype="center",scaletype="fitXY",有和没有adjustViewBounds="true"在imageview中以全尺寸显示位图

我的XML是这样的

<ImageView 
    android:layout_width="wrap_content" 
    android:adjustViewBounds="false" 
    android:scaleType="center" 
    android:layout_centerInParent="true" 
    android:layout_height="wrap_content" 
    android:id="@+id/player_imageview" /> 

例如, 这是我的图库应用程序如何显示它 This is how my Gallery app displays it

这是我的应用程序显示它如何 This is how my app displays it

任何帮助将不胜感激。谢谢。

+1

你试过match_parent? – XxGoliathusxX

+1

是的,我有。如果我添加“match_parent”,imageview将占据整个屏幕。我不想那样。我希望它只占用源位图的大小。 –

回答

0

我自己想出了这个问题的答案。我浏览了Gallery应用程序的Android源代码。 Link to the layout of Gallery app。他们在AbsoluteLayout中嵌入了自定义图像视图。由于AbsoluteLayout已被弃用,我将Imageview嵌入到FrameLayout中。

的解决方案是

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/player_imageview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FF000000" /> 
</FrameLayout> 

此的FrameLayout被放置在里面的RelativeLayout。因此,固定。谢谢。 :)

0

请试试这个。

<ImageView 
    android:layout_width="wrap_content" 
    android:adjustViewBounds="false" 
    android:scaleType="fitCenter" 
    android:layout_centerInParent="true" 
    android:layout_height="wrap_content" 
    android:id="@+id/player_imageview" /> 
+0

谢谢。但是那也行不通。我得到了同样的结果。 ( –

+0

ow我看到了,请将此行更改为android:scaleType =“fitCenter”':android:scaleType =“centerCrop” –