【发布时间】:2015-04-16 23:37:45
【问题描述】:
我希望使用可绘制资源图像为每个标记设置不同的图像。
我有的是这个。
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
TextView tv1 = (TextView) v.findViewById(R.id.tv1);
TextView tv2 = (TextView) v.findViewById(R.id.tv2);
Button btn = (Button) findViewById(R.id.button);
LatLng pos = marker.getPosition();
tv1.setText(marker.getTitle());
tv2.setText(marker.getSnippet());
ImageView image = ((ImageView) findViewById(R.id.image42));
return v;
}
这会为标记设置图像,但我希望它是每个标记的不同图像。
我正在考虑这样的 if/else 语句..
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
TextView tv1 = (TextView) v.findViewById(R.id.tv1);
TextView tv2 = (TextView) v.findViewById(R.id.tv2);
Button btn = (Button) findViewById(R.id.button);
LatLng pos = marker.getPosition();
tv1.setText(marker.getTitle());
tv2.setText(marker.getSnippet());
ImageView image = ((ImageView) findViewById(R.id.image42));
if (marker == OldMellifontAbbey){
image= image.setBackground(BitmapDescriptorFactory.fromResource(R.drawable.oldmellifont));
}
else{
}
return v;
}
});
欢迎提出任何建议。 谢谢。
好的,所以我想我正在做某事,但我仍然无法弄清楚。 我编辑的代码如下。
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
TextView tv1 = (TextView) v.findViewById(R.id.tv1);
TextView tv2 = (TextView) v.findViewById(R.id.tv2);
Button btn = (Button) findViewById(R.id.button);
LatLng pos = marker.getPosition();
tv1.setText(marker.getTitle());
tv2.setText(marker.getSnippet());
ImageView image = ((ImageView) findViewById(R.id.image42));
try{
Drawable drawable = getResources().getDrawable(R.drawable.oldmellifont);
image.setBackground(drawable);
}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Hairy ball sack!!!", Toast.LENGTH_LONG).show();
}
return v;
}
});
【问题讨论】:
-
根据您的文字设置
Marker title并检查if(marker.getTitle().equals("your text"))然后设置特定图像 -
谢谢伙计。关于如何从可绘制资源中设置图像的任何建议?
-
imageview.setImageResource(id); -
谢谢,但这要么不起作用,要么导致地图关闭。
标签: android google-maps google-maps-android-api-2