AndroidJava-未显示GoogleMaps FragmentActivity上的自定义视图

AndroidJava-未显示GoogleMaps FragmentActivity上的自定义视图,第1张

概述我试图在自定义视图中绘制一些东西进行测试,该视图已添加到GoogleMapsFragmentActivity中.但是不知何故,当我在模拟器中运行它时,我的CustomView似乎没有绘制,我尝试了新的RelativeLayout和MapLayout.有任何想法吗?我做错了什么?这是我的主要GoogleMapsFragmentActivity代码,由A

我试图在自定义视图中绘制一些东西进行测试,该视图已添加到GoogleMaps FragmentActivity中.但是不知何故,当我在模拟器中运行它时,我的CustomVIEw似乎没有绘制,我尝试了新的relativeLayout和MapLayout.有任何想法吗 ?我做错了什么 ?

这是我的主要GoogleMaps FragmentActivity代码,由Android模板自动生成:

public class GoogleMaps extends FragmentActivity implements OnMapReadyCallback {private GoogleMap mMap;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.Google_maps);    // Obtain the SupportMapFragment and get notifIEd when the map is ready to be used.    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()            .findFragmentByID(R.ID.map);    mapFragment.getMapAsync(this);    //relativeLayout relativeLayout = new relativeLayout(this);    //relativeLayout.addVIEw(new SpriteLayer(this));    MapVIEw map = new MapVIEw(this);    map.addVIEw(new SpriteLayer(this));}@OverrIDepublic voID onMapReady(GoogleMap GoogleMap) {    mMap = GoogleMap;    // Add a marker in Sydney and move the camera    LatLng sydney = new LatLng(-34, 151);    mMap.addMarker(new MarkerOptions().position(sydney).Title("Marker in Sydney"));    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));}}

那就是我的CustomVIEw代码:

public class SpriteLayer extends VIEw {Paint paint = new Paint();public SpriteLayer(Context context) {    super(context);    setwillNotDraw(false);}@OverrIDeprotected voID onMeasure(int wIDthMeasureSpec, int heightmeasureSpec) {    int desireDWIDth = 100;    int desiredHeight = 100;    int wIDthMode = MeasureSpec.getMode(wIDthMeasureSpec);    int wIDthSize = MeasureSpec.getSize(wIDthMeasureSpec);    int heightmode = MeasureSpec.getMode(heightmeasureSpec);    int heightSize = MeasureSpec.getSize(heightmeasureSpec);    int wIDth;    int height;    //Measure WIDth    if (wIDthMode == MeasureSpec.EXACTLY) {        //Must be this size        wIDth = wIDthSize;    } else if (wIDthMode == MeasureSpec.AT_MOST) {        //Can't be bigger than...        wIDth = Math.min(desireDWIDth, wIDthSize);    } else {        //Be whatever you want        wIDth = desireDWIDth;    }    //Measure Height    if (heightmode == MeasureSpec.EXACTLY) {        //Must be this size        height = heightSize;    } else if (heightmode == MeasureSpec.AT_MOST) {        //Can't be bigger than...        height = Math.min(desiredHeight, heightSize);    } else {        //Be whatever you want        height = desiredHeight;    }    //MUST CALL THIS    setMeasuredDimension(wIDth, height);}@OverrIDepublic voID onDraw(Canvas canvas) {    paint.setcolor(color.GREEN);    Rect rect = new Rect(20, 56, 200, 112);    canvas.drawRect(rect, paint );    Log.println(Log.ERROR,"Test ","One");}}

目前,我只看到带有标记的标准地图,仍然没有Rectangle 总结

以上是内存溢出为你收集整理的Android / Java-未显示GoogleMaps FragmentActivity上的自定义视图全部内容,希望文章能够帮你解决Android / Java-未显示GoogleMaps FragmentActivity上的自定义视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1093181.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存