当有活动完成绘制自己?

2023-09-13 02:07:15 作者:作业是狗,乱咬人

这也许有点一个奇怪的问题,但我只是`吨看着办吧。 基本上我有一个扩展视图,并覆盖了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.

现在的问题是,我不能老是让活动绘制位图在启动时。我尝试在的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.

它的工作原理,如果我设置的位图上的一个按钮preSS和调用invalitate(),所以我怀疑我试着画出前活动hasn`t完成绘制本身。

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视图类,应该工作。

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();
  }
相关推荐