Android/Java - Custom View on GoogleMaps FragmentActivity isnt shown(Android/Java - GoogleMaps FragmentActivity 上的自定义视图未显示)
问题描述
我正在尝试在自定义视图中绘制一些用于测试的东西,该视图已添加到 GoogleMaps FragmentActivity.但不知何故,当我在模拟器中运行它时,似乎我的 CustomView 不是绘图.我尝试使用新的 RelativeLayout 和 MapLayout.有任何想法吗 ?我做错了什么?
Im trying to draw some Stuff for testing in an Custom View, which is added to the GoogleMaps FragmentActivity. But somehow, when i run it in the emulator, it seems like my CustomView isnt drawing.I tried it with a new RelativeLayout and an MapLayout. Any ideas ? What did i do wrong ?
这是我的主要 GoogleMaps FragmentActivity 代码,从 Android 模板自动生成:
Heres my Main GoogleMaps FragmentActivity code, auto generated from Android templates :
这是我的自定义视图代码:
Thats my CustomView Code :
目前我只看到带有标记的标准地图,仍然没有矩形:(
Currently i only see the standard map with an marker on it, still no Rectangle :(
推荐答案
您需要测量所需的视图大小.你只是传递你收到的东西,可能是 0.
You need to measure the desired size of your view. You are just passing what you are receiving, which probably is 0.
另一种选择是使用 MATCH_PARENT 设置 LayoutParams,但我不确定这是否可行.
Another option is to set a LayoutParams with MATCH_PARENT, but I'm not sure if this will work.
您尝试做的是高级,您应该在尝试之前阅读一些教程.
What you are trying to do is advanced, you should read some tutorials before trying it.
这里有更多信息:https://developer.android.com/training/custom-views/custom-drawing.html
这篇关于Android/Java - GoogleMaps FragmentActivity 上的自定义视图未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!