[英]Bitmap in ImageView is cropped off the screen
我正在開發一個需要下載圖像並將其顯示在ImageView中的Android應用程序。 將位圖傳遞到主Java文件,然后將其添加到圖像視圖中,如下所示:
comic = (ImageView) findViewById(R.id.comic);
comic.setImageBitmap(c.getImageBitmap());
除了圖像的左側從屏幕上消失之外,此方法有效。 ImageView在ScrollView中,它可以保持正確的大小。 這意味着在ScrollView的右側有黑色空間,圖像在左側被切除。
ImageView的XML是這樣的:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/comic"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:src="@drawable/xkcdlogo" />
</HorizontalScrollView>
</ScrollView>
知道為什么我的圖片被剪掉了嗎?
謝謝!
您是否嘗試過設置android:scaleType =“ center”而不是android:layout_gravity =“ center”?
這將使圖像在ImageView中居中而不縮放。
android:scaleType =“ centerCrop”
最終對我有用的解決方案是將內部ImageView設置為具有比最大圖像更大的固定高度和寬度,添加大量填充,然后在xml中設置android:scrollX和android:scrollY來放置圖像我需要他們的地方。 這解決了圖像在水平滾動中被裁剪的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.