0

My question is: Is it possible to display graphics on AbsoluteLayout using ImageView without having to define the said ImageView in an XML file? The reason I'm asking this is because I'm making an application where the number of images on screen changes from time to time.

I want to create and define an ImageView object without calling this line: myImageView = (ImageView)v.findViewById(R.id.nothere);

Any information on whether I can generate an ImageView object in code (without any XML files) will be welcome.

user3154699
  • 67
  • 3
  • 11

2 Answers2

2

Is it possible to display graphics on AbsoluteLayout using ImageView without having to define the said ImageView in an XML file?

You are certainly welcome to create an ImageView widget in Java, using a suitable constructor, then call addView() on a ViewGroup to add the ImageView to it. There are a variety of methods on ImageView for setting the image to show, such as setImageResource().

However, AbsoluteLayout has been deprecated for about six years. Please do not use it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks. I was actually very cloes to figuring it out myself. I created a custom View and the only thing that was stopping me was the fact that I couldn't call the onDraw(Canvas canvas) method myself because there is no getCanvas() method. :) – user3154699 Sep 15 '15 at 22:32
0

Other than AbsoluteLayout being deprecated for sure easily.

With your absolute layout set something like this

ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.fdsafsf);
absoluteLayout.addView(imageView)
Ashley Alvarado
  • 1,078
  • 10
  • 17