绘制位图时仍使用XML查看 [英] Draw Bitmap When Still Using XML View

查看:210
本文介绍了绘制位图时仍使用XML查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我用我的main.xml在我的程序的视图,但我还需要能够通过编程来bimaps /绘图资源添加到屏幕上。有没有办法做到这一点?

So I am using my main.xml as a view in my program but I still need to be able to add bimaps/drawables to the screen through programming. Is there any way to do that?

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 }

这是有点儿什么我的onCreate样子(但有很多code为应用程序的目的)。

That is kinda what my onCreate looks like (but with a lot of code for the purpose of the app).

反正是有可能加我当前视图的视图或画布ONTOP?

Is there anyway to maybe add a View or Canvas ONTOP of my current view?

我是新来的位图和绘图为Android很抱歉,如果这是众所周知的,但我不能在任何地方找到一个体面的答案:P

I am new to bitmaps and drawables for android so sorry if this is commonly known, but I can't find a decent answer anywhere :P

谢谢,
   布兰登

Thanks, Brandon

推荐答案

创建(如果你想要把视图或另一个布局)一个标识在XML中的FrameLayout
也许你可以有你的onCreate()是这样的:

Create a Id to a framelayout in the xml (or another layout where you want to put the view) Maybe you can have your onCreate() something like this:

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

   //Init the framelayout from xml by id
   FrameLayout myFrameLayout = (FrameLayout) findViewById(R.id.myFrameLayout);

   //Create a new ImageView
   img_icon = new ImageView(this);
   img_icon.setImageResource(R.drawable.icon);
   img_icon.setAdjustViewBounds(true);
   img_icon.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

   //Add the newly created ImageView
   myFrameLayout.addView(img_icon);

}

这篇关于绘制位图时仍使用XML查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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