gpt4 book ai didi

带有 TextView 和按钮的 Android map

转载 作者:太空狗 更新时间:2023-10-29 14:29:51 28 4
gpt4 key购买 nike

在我的应用程序中,我想显示一个带指针的 map ,在指针上方我想显示一个带按钮的 TextView 。使用该按钮我想转到下一个 Activity 。以下是我的代码来显示点,但如何显示带有文本和按钮的点到它的右侧。以及如何为其编写 btn 操作

class MapOverlay extends com.google.android.maps.Overlay
{
public boolean draw(Canvas canvas, MapView mapView,boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);

//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();

mapView.getProjection().toPixels(p, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);

mapView.getProjection().toPixels(q, screenPts);
@SuppressWarnings("unused")
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.blue);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);
return true;
}
}



p = new GeoPoint((int) (latPt * 1E6),(int) (lngPt * 1E6));
Log.e("point p ",""+p);

mapController.animateTo(p);
mapController.setZoom(16);
mapView.invalidate();
mapView.setTraffic(true);
mapController = mapView.getController();

MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);

最佳答案

我是通过使用 View 而不是叠加层来实现的,因此您可以使用 addItem 为 map 中的每个项目添加一个新 View 。这是代码:

注解 View

public AnnotationView(final Context context,final Object object) {
super(context);
setOrientation(VERTICAL);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.map_overlay, this, true);

// Set the textview

lBubble = (LinearLayout) findViewById(R.id.lAnnotation);
txtPlace = ((TextView) (findViewById(R.id.txtPlace)));
txtPlace.setText(object.getName());

// set button touch listener

((ImageButton) (findViewById(R.id.btnPlace)))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Do anything
};
});
// add your overlay on mapview by geopoint

btnMarker = ((ImageButton) (findViewById(R.id.btnMarker)));
btnMarker.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
//Do anything };
});

setLayoutParams(new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, new GeoPoint(
(int) (object.getLatitude() * 1E6),
(int) (object.getLongitude() * 1E6)),
MapView.LayoutParams.BOTTOM_CENTER));
}

然后我创建它并添加到 map 中,如下所示:

overlay = new AnnotationView(this, object);
mapView.addView(overlay);

map_overlay 布局只是您想要在 map 上显示为叠加层(图像、按钮...)的线性布局

我只有缩放比例有问题,因为缩放时点会发生一点变化,我正在尝试解决它。​​

希望对你有帮助

干杯

关于带有 TextView 和按钮的 Android map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8060765/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com