botguide
botguide

Reputation: 139

Having trouble in setting image in imageview in xamarin.android

I am trying to set an image of 20KB in an image view . But I am not getting the image in the screen . I inserted the image in Resources/@drawable . But not displaying the image on the layout screen (.axml) . My .axml code is below:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <TextView
            android:text="Last Check-in"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView1"
            android:paddingLeft="20dp"
            android:paddingRight="30dp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
        <TextView
            android:text="Date"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/textView2"
            android:paddingLeft="50dp"
            android:paddingRight="50dp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <ImageView
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/imageView2" />
        <TextView
            android:text="Productivity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView1"
            android:paddingLeft="20dp"
            android:paddingRight="30dp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
        <ImageView
            android:src="@drawable/1happy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/fithappy" />
    </LinearLayout>
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1" />
</LinearLayout>

@drawablw/1happy is the image contained

Upvotes: 1

Views: 597

Answers (1)

Robert Bruce
Robert Bruce

Reputation: 1088

You should have a folder called "drawable" under your "Resources" folder by default when you created the project. Move the image to that folder. Then remove the "@drawable" folder, as a Xamarin project won't compile with an image in that folder name.

For a working example, see https://developer.xamarin.com/recipes/android/controls/imageview/display_an_image/

Upvotes: 1

Related Questions