![](/img/trans.png)
[英]Android: ImageView scale to screen width within a ScrollView
[英]Android ImageView in ScrollView shows white screen
我想顯示的image
比屏幕長 。
我在scroll view
使用ImageView
。 我得到一個白色的屏幕 ,該屏幕 可滾動到image
的height
,但是圖像本身未顯示 。
這是我正在使用的布局xml :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/test_image_content_description"
android:adjustViewBounds="true"
android:visibility="visible"
android:src="@drawable/test_image" />
</ScrollView>
test_image.png是一個文件,可以在應用程序的所有“ drawable
”文件夾中找到。
任何幫助將不勝感激!
在您的ScrollView
,
將android:layout_height="wrap_content"
更改為android:layout_height="math_parent"
您可以向您的imageview添加一個scaletype,例如使用android:scaleType="center"
將沒有縮放比例的圖像居中,然后您應從imageview中刪除代碼android:adjustViewBounds="true"
。 有關詳細信息,請參見ImageView.ScaleType
。 謝謝
好的,我發現了問題。 似乎問題在於圖像的高度為6000像素,Android願意顯示的最大尺寸(即使在ScrollView內部)也為4096(即使我添加了縮放比例)。
調整圖像大小后,顯示沒有問題。
謝謝大家的答復!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.