2016-12-01 27 views
1

我正在開發一個Android應用程序。在我的應用程序中,我需要像Facebook一樣的放大圖像功能。所以,我用這個庫 - https://github.com/chrisbanes/PhotoView。但是,我在第一次加載圖像時顯示完整圖像時遇到問題。在Android中顯示帶PhotoView的初始圖像

這是我如何設置PhotoViewAttacher到ImageView的

photoViewAttacher = new PhotoViewAttacher(imageView); 
    photoViewAttacher.setZoomable(true); 
    photoViewAttacher.update(); 

這是ImageView的

 <ImageView 

     android:id="@+id/item_details_image" 
     android:scaleType="fitCenter" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

的XML佈局我所試圖做的是我想要的圖像顯示整個畫面如果圖像大於屏幕尺寸。不管它有多大。但圖像可能比屏幕尺寸小。我只想在最初顯示完整圖像。但是上面的代碼給了我這個結果。

enter image description here

正如你可以看到的截圖,它不能顯示整個圖像。它只顯示部分。如果我想看到其他區域的圖像,我想滾動或滑動,因爲圖像最初不適合屏幕顯示。所以我試圖改變XML來初始顯示圖像的整個區域。這是我改爲的XML。

<ImageView 

     android:id="@+id/item_details_image" 
     android:scaleType="centerInside" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

正如你所看到的,我將高度從match_parent改爲wrap_content。縮放類型也是如此。當我改變它的時候,它會像這樣初始顯示完整的圖像。

enter image description here

它顯示了完整的圖像,但小。對我來說完全沒問題。這就是我想要的。問題在於縮放功能。當我放大時,圖像不能比圖像高度大。請參閱下面的截圖。

enter image description here

正如你可以在上面看到,它沒有顯示完整的圖像時,我放大了。 ImageView高度不變。

+0

我有同樣的問題。你找到解決方案嗎? – JensJensen

+0

在xml中使用PhotoView而不是ImageView。 –

回答

2
<ImageView 
     android:id="@+id/item_details_image" 
     android:scaleType="fitCenter" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

你需要match_parent高度或寬度