0
我在圖像視圖中有一個矩形圖像。我想在屏幕上適合不同的屏幕尺寸,同時保持縱橫比。ImageView填充不同的屏幕尺寸,但保持縱橫比
在較小的屏幕上它的工作正常,但它並沒有在大屏幕上拉伸。圖像底部留有一些空隙。
這是我的代碼:
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
LayoutParams params1 = new LayoutParam(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
mMainLayout = new LinearLayout(context);
mMainLayout.setLayoutParams(params);
backgroundImage = new ImageView(context);
backgroundImage.setId(0);
backgroundImage.setAdjustViewBounds(true);
backgroundImage.setScaleType(ScaleType.FIT_CENTER);
backgroundImage.setLayoutParams(params1);
backgroundImage.setImageResource(R.drawable.background_circles_en);
mMainLayout.addView(backgroundImage);
我用的fill_parent
,wrap_content
多scaleTypes多種組合:fitCenter
,centerInside
,他們都畫在正確的縱橫比的圖像,但它們都沒有實際規模圖像和ImageView本身,導致TextViews被一路推下屏幕,ImageView中的空白或圖像未縮放。
請給出正確的組合,以便它能夠適用於不同的屏幕尺寸。
它沒有工作的人。我以前也試過,但沒有改變。在大屏幕的頁面底部有相同的空間 – akashpatra
因爲您正在將包裝內容佈局參數設置爲圖像視圖,而不是將佈局參數設置爲參數。 – jeet
thnx jeet..it工作..但圖像正在向y軸伸展。我們怎麼能糾正這一點? – akashpatra