簡體   English   中英

ImageView沒有正確縮小圖像中心

[英]ImageView does not center scaled down images properly


我無法在ImageView中正確縮放圖像並使其居中。
向上擴展時,沒有問題,但是當縮小時,圖像不再顯示居中,並且ImageView的邊界是錯誤的,如下所示:

problem.png

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/stereomood_splash"
        android:scaleType="fitCenter"
        android:id="@+id/imageView1"
        android:layout_width="100dip"
        android:layout_height="200dip"></ImageView>
</LinearLayout>

這是一個錯誤,有沒有人找到解決方法?

您應該在此答案中設置android:adjustViewBounds="true"

您還需要將android:layout_widthandroid:layout_height設置為wrap_content ,否則我相信您的硬編碼邊界將覆蓋任何視圖邊界調整。

編輯:將此放在此處,因為它與遇到相同症狀的人相關。

此問題僅出現在XML編輯器中 - 在真實手機或模擬器上,圖像的大小和位置正確。 根據特定圖像和ImageView尺寸,編輯器預覽將顯示圖像調整不正確和/或超出視圖邊界。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM