Reputation:
i`m new in xamarin.android i want to know how can i set resources for my image view widget? i did put my images in Assets folder but i dont know how to use them please give an example thanks! here is my attempt without any result:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
ImageView img = FindViewById<ImageView>(Resource.Id.imageView1);
img.SetImageResource(Resource.Drawable.); // i cant find my images here
Upvotes: 0
Views: 4452
Reputation: 15816
In your project, the image should be placed in the Drawable
folder like this:
Then you can access your image by:
ImageView img = FindViewById<ImageView>(Resource.Id.myImage);
img.SetImageResource(Resource.Drawable.test);
Or set it in xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/myImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/test" />
</LinearLayout>
Upvotes: 1