-1
我試圖動態地構建一個佈局,因此它縮放並在所有屏幕尺寸和分辨率上看起來差不多相同。我通過以編程方式將我的視圖放入RelativeLayout
並根據某個因子縮放所有內容來完成此操作。RelativeLayout邊距縮小ImageView
雖然我在移動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);
}
任何想法是什麼造成這種情況?
的圖像,一切都將自動縮放。或者它是動態的,因爲在啓動時,你不知道你需要展示什麼? – banzai86
嘗試更改父佈局的重力 – JiTHiN