1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Drain Droids

Android Studio For Beginners.Mobile Apps.Android Games.

Wednesday, February 6, 2019

How to use ImageView in Android Studio


ImageView is used to show or display image in android studio application. It is easy to understand android studio ImageView .Unlike ImagebButton,  ImageView are not clickable. Does not have set onClick attribute which means you cannot click on it to open up another activity or page.

Imageview can be adjusted to fit different screen size options.

We are going to discuss about three things

1-Making plain ImageView and adjustment to fit the screen Size
2-Some ImageView Attribute
3- How I used Image to set background Design.
Let’s Begin

Making plain ImageView and adjustment to fit the screen Size






Step one- save your image on your desktop with a name. I named mine pett

Step two –copy and paste the image in your Drawable Folder.
Step Three- Click on design and Drag and drop the imagView to your layout.


Step Four –It will pop up an option asking to you locate your image,click on Project and locate your pett image. See below. You will have the image appeared on your design screen




Step five -At first, your image may appears somewhere in the middle, navigate to TEXT and adjust the height to get it adjusted to the top. In my case, I adjusted the height to 280dp

<ImageView
       
android:id="@+id/imageView"
       
android:layout_width="wrap_content"
       
android:layout_height="280dp"
       
app:srcCompat="@drawable/pett" />
</
android.support.constraint.ConstraintLayout>


ImageView Attribute

<ImageView
       
android:id="@+id/imageView"
       
android:layout_width="wrap_content"
       
android:layout_height="280dp"
       
app:srcCompat="@drawable/pett" />
</
android.support.constraint.ConstraintLayout>


Image Id –An ID which is used to identify the image in android studio.

Height and Width- You can adjust the height and the width of the image as suit you.

Src- This locate the drawable folder where the image is housed. In order word, the image source.


How to set image as background


1. Get your 540 x 960 Image size ready
2. Save the image with a name imagbackgr
3. Include this line of code android:background="@drawable/imagbackgr" in the tools:context and edit the image name to the name you save your image.In my case, i named it imagbackgr.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:background="@drawable/imagbackgr"
   
tools:context=".MainActivity">

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Hello World!"
       
app:layout_constraintBottom_toBottomOf="parent"
        
app:layout_constraintLeft_toLeftOf="parent"
       
app:layout_constraintRight_toRightOf="parent"
       
app:layout_constraintTop_toTopOf="parent" />

</
android.support.constraint.ConstraintLayout>