Android Game development - Imageview automatically shrinks at screen edge

╄→尐↘猪︶ㄣ 提交于 2019-12-25 11:30:44

问题


I have a bunch of dynamically created ImageViews representing different objects in a game, which is working fine. However if any Image reaches the edge of the screen, it shrinks. Looks like android is attempting to create a smooth transition, but this is not wanted.

I found another thread with the same issue here: Animation Drawable gets automatically shrinks at the corners ?, however his solution does not work for me, it only enhances the issue as it starts shrinking once the margin hits the screen edge.

This is my code:

final LayoutParams _updated_params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

_updated_params.setMargins((int)m_x, (int)m_y, 0, 0);

m_image.setLayoutParams(_updated_params);</code>

Where m_x/m_y is the absolute position of the image and m_image is an ImageView instance.

Does anyone know how I can turn off this automatic resizing?


回答1:


Add setScaleType

m_image.setScaleType(ScaleType.MATRIX);



回答2:


Use setScaleType

m_image.setScaleType(ScaleType.FIT_XY);


来源:https://stackoverflow.com/questions/17298549/android-game-development-imageview-automatically-shrinks-at-screen-edge

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