Activity 什么时候完成自己的绘制? [英] When has the Activity finished drawing itself?

查看:52
本文介绍了Activity 什么时候完成自己的绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个有点奇怪的问题,但我就是想不通.基本上,我有一个扩展 View 并覆盖 onDraw 方法的类,因此它绘制了一个位图.我想要做的是从图库中选择一张图片,将其发送并意图并在视图上绘制.

This maybe somewhat of a strange question but I just can`t figure it out. Basically I have a class that extends View and overrides the onDraw method so it draws a bitmap what it is called. What I want to do is when by choosing a picture from a gallery, send it through and intent and draw that on the View.

问题是我在启动时无法让Activity绘制位图.我尝试在 onCreate、onStart 中设置...没有任何效果.

The problem is that I can`t get the Activity to draw the bitmap when it is started. I try setting in in onCreate, onStart... nothing works.

如果我在按下按钮并调用 invalitate() 时设置位图,它会起作用,所以我怀疑我在 Activity 还没有完成绘制之前尝试绘制.

It works if I set the bitmap on a button press and calling invalitate(), so I suspect that I try to draw before the Activity hasn`t finished drawing itself.

有什么建议吗?

推荐答案

好吧,如果您在 onCreate 中实例化扩展 View 的类,那应该可行.

Well, if you instantiate the class that extends the View in your onCreate, that should work.

看看这个例子:

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set full screen view
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    customView = new CustomView(this);
    setContentView(customView);
    customView.requestFocus();
  }

这篇关于Activity 什么时候完成自己的绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆