Set image Uri for ImageView : ImageView « UI « Android






Set image Uri for ImageView

  

package app.test;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;

public class Test extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView imgView = (ImageView) findViewById(R.id.image3);

    imgView.setImageURI(Uri.parse("file://mnt/sdcard/d2.jpg"));
  }
}

//main.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- This file is at /res/layout/list.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"  android:layout_height="fill_parent">
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"  android:layout_height="fill_parent">

  <ImageView android:id="@+id/image1"
    android:layout_width="wrap_content"  android:layout_height="wrap_content"
    android:src="@drawable/icon"
    />

  <ImageView android:id="@+id/image2"
    android:layout_width="125dip"  android:layout_height="25dip"
    android:src="#555555"
    />
  </LinearLayout>
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"  android:layout_height="fill_parent">

  <ImageView android:id="@+id/image3"
    android:layout_width="wrap_content"  android:layout_height="wrap_content"
    />

  <ImageView android:id="@+id/image4"
    android:layout_width="wrap_content"  android:layout_height="wrap_content"
    android:src="@drawable/icon"
    android:scaleType="centerInside"
    android:maxWidth="35dip"  android:maxHeight="50dip"
    />

  </LinearLayout>
</LinearLayout>

   
    
  








Related examples in the same category

1.Set ImageView width, height
2.extends ImageView
3.Load image with ImageView
4.Using ImageView within ListActivity
5.Using ImageView to display image and reference Image resource in layout xml file
6.ImageView background
7.Set Layout Parameters, Scale Type, background for ImageView
8.Using ImageView to display Image
9.ImageView click listener
10.Set Image resource for ImageView
11.Set Image Bitmap for ImageView
12.Adding Touch Listener to ImageView
13.Demonstrates setting size constraints on android.widget.ImageView
14.Create ImageView
15.Create an image view, given a drawable. you can set the max size of this imageview as well.
16.download images from the Internet and binds those with the provided ImageView.
17.Choose a Picture