free web tracker
Course Content
Java Programming Basics for Android
Learn the basics of Java programming for Android app development using Android Studio. This guide covers key concepts like variables, loops, and classes to help you start building your first Android apps with confidence. Perfect for beginners!
0/10
User Interaction and App Logic
Learn how to make your app respond to users! This section covers handling clicks, getting input, showing messages, switching screens, and saving simple data. A perfect start to build interactive Android apps with real logic.
0/10
Advanced Layouts and Components
Learn to build modern Android UIs using advanced layouts like RecyclerView, CardView, TabLayout, and more. This section helps beginners create beautiful, interactive, and user-friendly app interfaces step by step.
0/10
Media and Resources
Learn how to manage media and resources in Android Studio. This section covers adding audio, images, video, using drawables, custom fonts, and handling runtime permissions—essential for building rich, engaging Android applications.
0/4
Mastering Java Android Development – Beginner

In Android development, ImageView is a commonly used widget to display images. This tutorial will show you how to use ImageView in Java with Android Studio, including how to display images from the drawable folder, and how to load images from a URL using a library like Glide.

Step 1: Add ImageView to Layout XML

Open your activity_main.xml and add the following:

<ImageView
    android:id="@+id/myImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/sample_image"
    android:contentDescription="Sample Image"
    android:layout_gravity="center"
/>

Make sure you have an image named sample_image.jpg or sample_image.png inside the res/drawable/ folder.

Step 2: Reference ImageView in Java Code

Open your MainActivity.java and use the following code:

import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    ImageView myImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myImageView = findViewById(R.id.myImageView);
        
        // Optional: Set image programmatically
        myImageView.setImageResource(R.drawable.sample_image);
    }
}

Load Image from URL (Using Glide Library)

To load images from a URL, add Glide dependency in your build.gradle:

implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'

Then load the image like this:

import com.bumptech.glide.Glide;

// Inside onCreate()
String imageUrl = "https://example.com/image.jpg";
Glide.with(this)
     .load(imageUrl)
     .into(myImageView);

Final Tips:

    • Always use contentDescription for accessibility.
    • Use wrap_content or match_parent wisely to control image size.
    • Use Glide or Picasso to load large images efficiently.