我正在尝试动态构建布局,因此它可以在所有屏幕尺寸和分辨率上进行缩放和看起来或多或少相同。我这样做是通过以编程方式将我的视图放在RelativeLayout
中并根据某个因素扩展所有内容。
我在移动ImageView
时注意到一些奇怪的事情,边距值越大,ImageView
越小。当试图将东西放在正确的位置和大小时,这会非常烦人。
private void initializeObjects() {
Display display = getWindowManager().getDefaultDisplay();
Point screenSize = new Point();
display.getSize(screenSize);
float scale = screenSize.x / ( (screenSize.x < 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);
}
知道造成这种情况的原因是什么?
答案 0 :(得分:0)
使用
android:layout_height="720px"
android:layout_height="743px"
main_layout.xml 中的以使图片不缩小