I am making a 2D platformer type game. I made a ImageView using JAVA, that Is supposed to be about twice the size of the screen horizontally.
However, when the ImageView is displayed no matter the size of the Image, it keeps re-sizing to fit my screen . Note that I am not using XML, but I am purely using JAVA. How can I prevent this?
Here is the code:
ConstraintLayout gameLayout;
gameLayout = findViewById(R.id.gameLayout);
ImageView map = new ImageView(this);
map.setImageResource(R.drawable.tutorial_map);
map.setX(0);
map.setY(0);
gameLayout.addView(map);
Feel free to edit further if necessary.
Use map.setScaleType(ScaleType.FIT_XY);
or
You can also use map.setAdjustViewBounds(true);
Make sure you use map.setBackgroundResource(R.drawable.tutorial_map) instead of map.setImageResource(R.drawable.tutorial_map).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With