The following code shows some XML examples of ImageViews, followed by
some code that shows how to create an ImageView
.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/image3" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
The following Java code sets the image from resource.
package com.java2s.app; // www . j a v a 2 s.c o m import android.app.Activity; import android.os.Bundle; import android.widget.ImageView; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imgView = (ImageView) findViewById(R.id.image3); imgView.setImageResource(R.drawable.ic_launcher); } }