Note that there are some explanatory texts on larger screens.

plurals
  1. PORelativeLayout margin shrinks ImageView
    text
    copied!<p>I'm trying to dynamically build a layout, so it scales and looks more or less identical on all screen sizes and resolutions. I do this by programmatically placing my views inside a <code>RelativeLayout</code> and scaling everything according to a certain factor.</p> <p>I noticed something strange when moving an <code>ImageView</code> around though, the bigger the values on margins get, the smaller the <code>ImageView</code> gets. This gets really annoying when trying to get things at right place and size.</p> <pre><code>private void initializeObjects() { Display display = getWindowManager().getDefaultDisplay(); Point screenSize = new Point(); display.getSize(screenSize); float scale = screenSize.x / ( (screenSize.x &lt; screenSize.y) ? 480 : 800 ); // Scale according to Galaxy S II resolution RelativeLayout screenLayout = (RelativeLayout) findViewById(R.id.main_layout); mRobotView = new ImageView(getApplicationContext()); mRobotView.setImageResource(R.drawable.soomla_logo_new); // a 743 x 720 png mRobotView.setScaleX(scale * 100 / 743); // Make sure the image is 100 "units" in size mRobotView.setScaleY(scale * 100 / 720); mRobotView.setPivotX(scale * 100 / 743); // reset the image origin according to scale mRobotView.setPivotY(scale * 100 / 720); RelativeLayout.LayoutParams robotParams = new RelativeLayout.LayoutParams(743, 720); robotParams.leftMargin = 0xDEADBEEF; // The bigger these get the smaller the view gets robotParams.topMargin = 0xDEADBEEF; screenLayout.addView(mRobotView, robotParams); } </code></pre> <p>Any idea what's causing this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload