我正在開發一個Android應用程序。我以編程方式創建視圖,並且對於此應用程序是必需的,因爲它應該是動態的。我可以將資源按照hdpi,mdpi和ldpi分配,但我想知道如何設置視圖的寬度和高度,以便在所有Android屏幕上顯示正確。目前我正在使用密度因子如下。如何創建將在Android的多個屏幕上運行的視圖?
ImageView imgMainPic = new ImageView(this);
RelativeLayout.LayoutParams rllpImg =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
(int)(440*Global.nDensity));
rllpImg.addRule(RelativeLayout.ALIGN_TOP,mainRelativeLyt.getId());
imgMainPic.setId(1);
imgMainPic.setLayoutParams(rllpImg);
imgMainPic.setBackgroundResource(R.drawable.pic1);
mainRelativeLyt.addView(imgMainPic);