开发者

Draw Bitmap When Still Using XML View

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);
 }

That is k开发者_如何学Pythoninda what my onCreate looks like (but with a lot of code for the purpose of the app).

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

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


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);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜