简体   繁体   中英

how to set resource of imageView in xamarin.android?

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM