0

我使用畢加索來檢索位圖圖像以用作標記圖標,並且它可以成功應用。但我需要動態增加所有設備的自定義標記的大小。因爲在我的代碼下面,它在某些設備上工作正常,但在其他一些設備中,標記非常大。動態增加谷歌地圖中自定義標記的大小 - Android

這裏是我的代碼

dest = new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()); 
markerOption = new MarkerOptions().position(dest); 
location_marker = mMap.addMarker(markerOption); 
Target target = new PicassoMarker(location_marker); 
targets.add(target); 

Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(84, 125).into(target); 
mMarkersHashMap.put(location_marker, myMarker); 

請幫我解決這個問題。

在此先感謝。

+0

有沒有解決方法?任何解決方案將不勝感激。 –

回答

2

按照你的代碼提供,你可以修改你在resize()在此行傳遞的值:

Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(84, 125).into(target); 

我嘗試過了,你的代碼顯示了這一點:

enter image description here

然後我修改了resize()的值,如下所示:

Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(184, 1125).into(target); 

而事實證明這樣的:

enter image description here

值在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); 

- 這是一個很好的例子,只需測量佈局以將其用作如何調整圖像大小的參考。

+0

是的,我使用'resize(84,125)',它在一些設備上運行良好。但我嘗試了其他一些設備,標記非常大。但我需要動態增加所有設備的自定義標記的大小。所以當運行這個應用程序時,標記會調整設備的屏幕。我該怎麼辦? –

+0

你應該想到的公式,將提供您正在尋找的值,其中寬度和高度取決於屏幕大小..我認爲這[回答](http://stackoverflow.com/a/4798597/4625829)可能會爲你工作。 :) –