ImageView does not center scaled down images properly
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>
Is this a bug, and has anyone found a workaround?
You should set android:adjustViewBounds="true"
as in this answer.
You also need to set either android:layout_width
or android:layout_height
to be wrap_content
, otherwise I believe your hard-coded bounds will override any view bounds adjustments.
Edit: Put this here as it's relevant to those encountering the same symptoms.
This problem is only present in the XML editor - on a real phone or emulator the image is sized and positioned correctly. Depending on the particular image and ImageView
dimensions, the editor preview will show the image incorrectly resized and/or out of the view bounds.
精彩评论