Android / Java-未显示GoogleMaps FragmentActivity上的自定义视图
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android / Java-未显示GoogleMaps FragmentActivity上的自定义视图,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2553字,纯文字阅读大概需要4分钟。
内容图文
![Android / Java-未显示GoogleMaps FragmentActivity上的自定义视图](/upload/InfoBanner/zyjiaocheng/690/fa8f0f580032407a9671242b428e6b54.jpg)
我试图在自定义视图中绘制一些东西进行测试,该视图已添加到GoogleMaps FragmentActivity中.但是不知何故,当我在模拟器中运行它时,我的CustomView似乎没有绘制,我尝试了新的RelativeLayout和MapLayout.有任何想法吗 ?我做错了什么 ?
这是我的主要GoogleMaps FragmentActivity代码,由Android模板自动生成:
public class GoogleMaps extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected 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));
}
@Override
public 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);
}
@Override
protected 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);
}
@Override
public 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上的自定义视图所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。