Brandon
Brandon

Reputation: 703

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 kinda 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

Upvotes: 0

Views: 701

Answers (1)

Weldeborn
Weldeborn

Reputation: 114

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

}

Upvotes: 1

Related Questions