[su_youtube_advanced url=”https://www.youtube.com/watch?v=rFgaW7ZjVKU”]
In previous chapter we played around little bit with with text view
Now the other view we wanna learn about is image view
Now here’ the code for image view
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image" android:scaleType="fitEnd" />
Now look at the line of code one at a time
XML elements start with the open angle bracket and then name of the view and then list of attributes then its followed by forward slash then closing angle bracket
When you wrote the xml for text view it displays the text on the screen so now when we write ImageView it display image on the screen
There are list of attributes available on android for image view.
We gonna look at some attributes
Android source the path of image to display on screen
android:src=”@drawable/image”
Here we use @ symbol which referencing the resource in an android app and drawable is the resource type
We don’t include the file extension, You don’t need to add whether its a jpg,png or any other type just write the name of file.
If you are going to use the image in android studio then you have to add it manually first in to the drawable folder,
If i try to referencing an image which don’t exist in drawable folder it generates an error because of invalid image path.
Next you see, Scale type attribute it used to scale the image and mostly used attribute in image view.
You can scale the image, You can add background , you can add border and much more
Go try yourself.
Believe me or not professional developers never memorize everything!
No comments:
Post a Comment