按照你的代碼提供,你可以修改你在resize()
在此行傳遞的值:
Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(84, 125).into(target);
我嘗試過了,你的代碼顯示了這一點:
![enter image description here](https://i.stack.imgur.com/BLXLl.png)
然後我修改了resize()
的值,如下所示:
Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(184, 1125).into(target);
而事實證明這樣的:
![enter image description here](https://i.stack.imgur.com/2Jran.png)
值在resize()
一切都取決於你通過。 ;)
編輯
如果您關注的是什麼值傳遞取決於屏幕尺寸,你可以參考來自不同的崗位,以這種answer。這就是它所說的 -
你可以用代碼LayoutParams
做到這一點。不幸的是,沒有辦法通過XML來指定百分比(不是直接的,你可以用權重來搞亂,但這並不總是有幫助,它不會保持你的寬高比),但這應該適用於你:
//assuming your layout is in a LinearLayout as its root
LinearLayout layout = (LinearLayout)findViewById(R.id.rootlayout);
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.image);
int newHeight = getWindowManager().getDefaultDisplay().getHeight()/2;
int orgWidth = image.getDrawable().getIntrinsicWidth();
int orgHeight = image.getDrawable().getIntrinsicHeight();
//double check my math, this should be right, though
int newWidth = Math.floor((orgWidth * newHeight)/orgHeight);
//Use RelativeLayout.LayoutParams if your parent is a RelativeLayout
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
newWidth, newHeight);
image.setLayoutParams(params);
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
layout.addView(image);
- 這是一個很好的例子,只需測量佈局以將其用作如何調整圖像大小的參考。
有沒有解決方法?任何解決方案將不勝感激。 –