Android画布填充背景色(Canvas应用程序) [英] Android canvas fill background color (Canvas application)

查看:2014
本文介绍了Android画布填充背景色(Canvas应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过以下代码,我有一些疑问.

By having the following codes, I have some questions.

public class MainActivity extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView( new View(this) {
         Paint mPaint = new Paint();

         @Override
         protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);


            int width = this.getWidth();
            int height = this.getHeight();
            int radius = width > height ? height/2 : width/2;
            int center_x = width/2;
            int center_y = height/2;

            // prepare a paint
            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setStrokeWidth(5);
            mPaint.setAntiAlias(true);

            // draw a rectangle
            mPaint.setColor(Color.BLUE);
                mPaint.setStyle(Paint.Style.FILL); //fill the background with blue color
            canvas.drawRect(center_x - radius, center_y - radius, center_x + radius, center_y + radius, mPaint);
            // draw some text and rotation
            mPaint.setTextSize(50);
            mPaint.setTextAlign(Paint.Align.CENTER);
            mPaint.setColor(Color.BLACK);
            canvas.drawText( "Hello World" , center_x , center_y, mPaint);
         }
      });
    }
}

Q1:如何在框架中填充蓝色? (单词仍然出现)

Q1: How can I fill blue colour in the frame? (The words still appear)

Q2:此应用程序中有多少个视图和曲面?如何在应用程序中计算这些数字?

Q2: How many views and surfaces in this app? How can I count these in the app?

Q3:此应用程序中有多少个窗口?

Q3: How many windows in this app?

Q4:在代码中,我没有看到任何位图对象. 但是,我认为位图是我可以真正在上面绘制东西的对象.是我的 理解不正确? 一种可能是Canvas构造函数在更新位图时进行初始化.

Q4: In the code, I dont see any bitmap object in it. However, I thought that bitmap is the object that I can really draw things on it. Is my understanding incorrect? One possibility is that Canvas constructor initializes bitmap when it is newed.

Q5:我知道这些图形化的东西最终会浮出水面,然后传递给 表面助剂,用于最终合成.它在我的代码中的什么位置?

Q5: I knew that these graphic thing will finally go to surface and then pass to surfaceflinger for final composition. Where does it locate in my code?

感谢您的回复.

推荐答案

五个问题.让我们看看我能为您提供哪些帮助.

Five questions. Let's see where I can help.

Q1:告诉Paint填充矩形:paint.setStyle(Paint.Style.FILL);

Q1: Tell the Paint to fill the rectangle: paint.setStyle(Paint.Style.FILL);

Q2:我只能看到您以编程方式创建的一个视图.您为什么要计算观看次数?

Q2: I see only the one view you create programmatically. Why would you like to count the views?

第3季度:再一次:

Q4:通过用Canvas包装它们来绘制可变的位图.实际绘制的方法是Canvas

Q4: You draw an mutable bitmaps by wrapping them with a Canvas. The method to actually draw are part of Canvas

Q5:您显示的代码是活动的一部分.该活动由Android调用.这是您进入应用程序的入口点.

Q5: The code you show is part of an Activity. The Activity is called by Android. It's your entry point into your App.

这篇关于Android画布填充背景色(Canvas应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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