Image in ImageView is stretched - Android

我是研究僧i 提交于 2019-12-04 16:05:11

FIT_XY will stretch your image to fit all yout ImageView. Use scale type fitCenter to preserve aspect ratio by placing the image in center if your ImageView

q1Image.setScaleType(ScaleType.FIT_CENTER);

Refer to http://developer.android.com/reference/android/widget/ImageView.ScaleType.html For other options.

Your scaling the Image wrong. Here are all scaletypes:

Top row (l-r) center, centerCrop, centerInside.

Bottom row (l-r): fitCenter, fitStart, fitEnd, fitXY.

You probably need fitCenter:

q1Image.setScaleType(ScaleType.FIT_CENTER);

Without the full layout XML this is just speculation, but seeing as you don't appear to have fixed the problem by changing the scale type, here are some other suggestions:

  1. Wouldn't it be better if the layout_weight of the ImageView was zero?

  2. Are you specifying android:stretchColumns on the TableLayout?

  3. The image looks like it is being stretched to match the width of the text below. How many columns have you got in your table? It looks like the text in the other rows is in column 0 (as is the image in your first row) and the text in the first row is in column 1. If you want to leave column zero blank for the other rows, you need to specify android:layout_column on the text views.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!