You're building your layout in two different ways here.
- You have an XML layout containing your
ImageView
, but you never reference that XML layout anywhere in code, so Android never loads it (and therefore you can't access it). - You also create a layout in Java code by creating a new
LinearLayout
object and adding other views to it. This layout has noImageView
.
When you call SetContentView()
here:
SetContentView (layout);
You're telling Android to use the layout you created in code. If you want to use the XML layout, you can change to:
SetContentView(Resource.Layout.Main);
(Replacing Main
with the actual name of your XML file.)
Otherwise, you'd need to add the ImageView
in your Java code. But you probably don't want to mix and match XML layouts with Java code layouts.
Also note that you must call SetContentView()
before calling FindViewById()
.
You might also want to read through Xamarin's Resource Layouts tutorial.