SlideShare a Scribd company logo
9
Most read
10
Most read
16
Most read
Android Graphics
Topics
• Android Graphics
• Drawables
> Using an image saved in your project resources
> Using an XML file that defines the Drawable
properties
• ShapeDrawable
Android Graphics
Android Graphics Support
• Android graphics are powered by
> A custom 2D graphics library
> OpenGL ES 1.0 for high performance 3D graphics.
• The most common 2D graphics APIs can be
found in the drawable package.
• OpenGL APIs are available from the Khronos
OpenGL ES package, plus some Android
OpenGL utilities.
Drawables
What is a Drawable?
• A Drawable is a general abstraction for
"something that can be drawn."
• Drawable class extends to define a variety of
specific kinds of drawable graphics, including
> BitmapDrawable, ShapeDrawable, PictureDrawable,
LayerDrawable, and several more.
• You can also extend these to define your own
custom Drawable objects that behave in unique
ways.
Three ways to define & instantiate
Drawables
• Using an image saved in your project resources
• Using an XML file that defines the Drawable
properties
• Using the normal class constructors.
Drawables:
Using an image saved in
your project resources
Creating from Resource Images
• A simple way to add graphics by referencing an
image file from your project resources.
• Supported file types are
> PNG (preferred), JPG (acceptable) and GIF
(discouraged).
• Preferred technique for application icons, logos,
or other graphics such as those used in a game
• To use an image resource, just add your file to
the res/drawable/ directory of your project
> From there, you can reference it from your code or
your XML layout using a resource ID, which is the file
name without the file type extension
Build an ImageView that uses an image from
drawable resources and add it to the layout
LinearLayout mLinearLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.my_image);
i.setAdjustViewBounds(true); // set the ImageView bounds to match the
// Drawable's dimensions
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Add the ImageView to the layout and set the layout as the content view
mLinearLayout.addView(i);
setContentView(mLinearLayout);
}
Handle your image resource as a Drawable
object
Resources res = mContext.getResources();
Drawable myImage = res.getDrawable(R.drawable.my_image);
Add a resource Drawable to an ImageView in
the XML layout
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#55ff0000"
android:src="@drawable/my_image"/>
Drawables:
Using XML
Creating from Resource XML
• If there is a Drawable object that you'd like to
create, which is not initially dependent on
variables defined by your application code or
user interaction, then defining the Drawable in
XML is a good option.
• Even if you expect your Drawable to change its
properties during the user's experience with
your application, you should consider defining
the object in XML, as you can always modify
properties once it is instantiated.
Creating from Resource XML
• Once you've defined your Drawable in XML,
save the file in the res/drawable/ directory of
your project.
• Then, retrieve and instantiate the object by
calling Resources.getDrawable(), passing it the
resource ID of your XML file.
XML that defines a TransitionDrawable
• Let's assume below is saved as
res/drawable/expand_collapse.xml.
<transition
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/image_expand">
<item android:drawable="@drawable/image_collapse">
</transition>
XML that defines a TransitionDrawable
Resources res = mContext.getResources();
TransitionDrawable transition = (TransitionDrawable)
res.getDrawable(R.drawable.expand_collapse);
ImageView image =
(ImageView) findViewById(R.id.toggle_image);
image.setImageDrawable(transition);
The above code will instantiate the
TransitionDrawable and set it as the content of an
ImageView
ShapeDrawable
ShapeDrawable
• When you want to dynamically draw some two-
dimensional graphics, a ShapeDrawable object
will probably suit your needs.
• With a ShapeDrawable, you can
programmatically draw primitive shapes and
style them in any way imaginable.
Thank you

More Related Content

What's hot (20)

PDF
Android Location and Maps
Jussi Pohjolainen
 
PPTX
Android Widget
ELLURU Kalyan
 
PPTX
Introduction to Node.js
Vikash Singh
 
PPTX
Android - Application Framework
Yong Heui Cho
 
PPTX
Android UI
nationalmobileapps
 
PDF
Android ui layout
Krazy Koder
 
PPTX
Introduction to android
zeelpatel0504
 
PPTX
Android app development ppt
saitej15
 
PPT
Android Architecture
deepakshare
 
PPTX
Back face detection
Pooja Dixit
 
ODP
Introduction to Virtualization
Rahul Hada
 
PDF
Creating simple component
priya Nithya
 
PPTX
3 d display methods
Shami Al Rahad
 
PDF
Android activities & views
ma-polimi
 
PDF
Design Patterns for mobile apps
Ivano Malavolta
 
PPT
Communication primitives
Student
 
PDF
Multichannel User Interfaces
Icinetic
 
PDF
Android notification
Krazy Koder
 
PPTX
Content provider in_android
PRITI TELMORE
 
PPTX
Introduction to Android ppt
Taha Malampatti
 
Android Location and Maps
Jussi Pohjolainen
 
Android Widget
ELLURU Kalyan
 
Introduction to Node.js
Vikash Singh
 
Android - Application Framework
Yong Heui Cho
 
Android UI
nationalmobileapps
 
Android ui layout
Krazy Koder
 
Introduction to android
zeelpatel0504
 
Android app development ppt
saitej15
 
Android Architecture
deepakshare
 
Back face detection
Pooja Dixit
 
Introduction to Virtualization
Rahul Hada
 
Creating simple component
priya Nithya
 
3 d display methods
Shami Al Rahad
 
Android activities & views
ma-polimi
 
Design Patterns for mobile apps
Ivano Malavolta
 
Communication primitives
Student
 
Multichannel User Interfaces
Icinetic
 
Android notification
Krazy Koder
 
Content provider in_android
PRITI TELMORE
 
Introduction to Android ppt
Taha Malampatti
 

Viewers also liked (20)

PDF
new_age_graphics_android_x86
Droidcon Berlin
 
PDF
The Android graphics path, in depth
Chris Simmonds
 
PPT
Introduction to Android Fragments
Sergi Martínez
 
PDF
Design and Concepts of Android Graphics
National Cheng Kung University
 
PPTX
Presentation on Android operating system
Salma Begum
 
PDF
android drawable
ukayare
 
PPTX
Android Web app
Sumit Kumar
 
PPT
Android graphics
dcshi
 
DOCX
Android Basic Tutorial
Smartmonk
 
PDF
Android Vector Drawable
Phearum THANN
 
PDF
Android resource
Krazy Koder
 
PDF
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
PDF
Android Vector drawable
Oleg Osipenko
 
PDF
Революционный Android. Ищем замену фрагментам
Rambler Android
 
PDF
Vector Drawable API. Возможности применения
Rambler Android
 
PDF
Android security
Krazy Koder
 
PPTX
Android Material Design Quick Presentation
Deimantas Brandišauskas
 
PDF
Android complete basic Guide
AKASH SINGH
 
PDF
Material Design
Arya Padte
 
PPTX
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Bin Chen
 
new_age_graphics_android_x86
Droidcon Berlin
 
The Android graphics path, in depth
Chris Simmonds
 
Introduction to Android Fragments
Sergi Martínez
 
Design and Concepts of Android Graphics
National Cheng Kung University
 
Presentation on Android operating system
Salma Begum
 
android drawable
ukayare
 
Android Web app
Sumit Kumar
 
Android graphics
dcshi
 
Android Basic Tutorial
Smartmonk
 
Android Vector Drawable
Phearum THANN
 
Android resource
Krazy Koder
 
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
Android Vector drawable
Oleg Osipenko
 
Революционный Android. Ищем замену фрагментам
Rambler Android
 
Vector Drawable API. Возможности применения
Rambler Android
 
Android security
Krazy Koder
 
Android Material Design Quick Presentation
Deimantas Brandišauskas
 
Android complete basic Guide
AKASH SINGH
 
Material Design
Arya Padte
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Bin Chen
 
Ad

Similar to Android graphics (20)

PDF
Glide usage tips
LINE Corporation
 
PDF
Drupal Recipes: Building Image Galleries with jQuery and Flickr
Ben Shell
 
ODP
Android App Development - 04 Views and layouts
Diego Grancini
 
PPTX
OpenStack Glance
Deepti Ramakrishna
 
PPTX
Material Design Android
Samiullah Farooqui
 
PDF
Introduction to Andriod Studio Lecture note: Android Development Lecture 1.pdf
AliyuIshaq2
 
PPTX
Adapter and adapter views that are used in android
JinalBhagat2
 
PPTX
Android Custom Views
Babar Sanah
 
PPTX
Developing an object detector solution with Azure Custom Vision .NET SDK
Luis Beltran
 
PPTX
Unit 2 part for information technology1 4.pptx
shambelworku8
 
PPTX
2.6 flickr, image list, and network objects
allenbailey
 
PDF
Android Materials Design
Mohammad Aljobairi
 
PDF
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Jordan Open Source Association
 
PPTX
Swift Tableview iOS App Development
Ketan Raval
 
PDF
Top Tips for Android UIs - Getting the Magic on Tablets
Motorola Mobility - MOTODEV
 
PDF
Create an image classifier with azure custom vision net sdk
Luis Beltran
 
PPT
Canvas in html5 - TungVD
Framgia Vietnam
 
PPT
Android Ui
Jetti Chowdary
 
PPT
Android UI
mailalamin
 
PDF
Android app material design from dev's perspective
DeSmart Agile Software House
 
Glide usage tips
LINE Corporation
 
Drupal Recipes: Building Image Galleries with jQuery and Flickr
Ben Shell
 
Android App Development - 04 Views and layouts
Diego Grancini
 
OpenStack Glance
Deepti Ramakrishna
 
Material Design Android
Samiullah Farooqui
 
Introduction to Andriod Studio Lecture note: Android Development Lecture 1.pdf
AliyuIshaq2
 
Adapter and adapter views that are used in android
JinalBhagat2
 
Android Custom Views
Babar Sanah
 
Developing an object detector solution with Azure Custom Vision .NET SDK
Luis Beltran
 
Unit 2 part for information technology1 4.pptx
shambelworku8
 
2.6 flickr, image list, and network objects
allenbailey
 
Android Materials Design
Mohammad Aljobairi
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Jordan Open Source Association
 
Swift Tableview iOS App Development
Ketan Raval
 
Top Tips for Android UIs - Getting the Magic on Tablets
Motorola Mobility - MOTODEV
 
Create an image classifier with azure custom vision net sdk
Luis Beltran
 
Canvas in html5 - TungVD
Framgia Vietnam
 
Android Ui
Jetti Chowdary
 
Android UI
mailalamin
 
Android app material design from dev's perspective
DeSmart Agile Software House
 
Ad

More from Krazy Koder (20)

PPT
2310 b xd
Krazy Koder
 
PPT
2310 b xd
Krazy Koder
 
PPT
2310 b xd
Krazy Koder
 
PPT
2310 b xc
Krazy Koder
 
PPT
2310 b xb
Krazy Koder
 
PPT
2310 b 17
Krazy Koder
 
PPT
2310 b 16
Krazy Koder
 
PPT
2310 b 16
Krazy Koder
 
PPT
2310 b 15
Krazy Koder
 
PPT
2310 b 15
Krazy Koder
 
PPT
2310 b 14
Krazy Koder
 
PPT
2310 b 13
Krazy Koder
 
PPT
2310 b 12
Krazy Koder
 
PPT
2310 b 11
Krazy Koder
 
PPT
2310 b 10
Krazy Koder
 
PPT
2310 b 09
Krazy Koder
 
PPT
2310 b 08
Krazy Koder
 
PPT
2310 b 08
Krazy Koder
 
PPT
2310 b 08
Krazy Koder
 
PPT
2310 b 07
Krazy Koder
 
2310 b xd
Krazy Koder
 
2310 b xd
Krazy Koder
 
2310 b xd
Krazy Koder
 
2310 b xc
Krazy Koder
 
2310 b xb
Krazy Koder
 
2310 b 17
Krazy Koder
 
2310 b 16
Krazy Koder
 
2310 b 16
Krazy Koder
 
2310 b 15
Krazy Koder
 
2310 b 15
Krazy Koder
 
2310 b 14
Krazy Koder
 
2310 b 13
Krazy Koder
 
2310 b 12
Krazy Koder
 
2310 b 11
Krazy Koder
 
2310 b 10
Krazy Koder
 
2310 b 09
Krazy Koder
 
2310 b 08
Krazy Koder
 
2310 b 08
Krazy Koder
 
2310 b 08
Krazy Koder
 
2310 b 07
Krazy Koder
 

Recently uploaded (20)

PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 

Android graphics

  • 2. Topics • Android Graphics • Drawables > Using an image saved in your project resources > Using an XML file that defines the Drawable properties • ShapeDrawable
  • 4. Android Graphics Support • Android graphics are powered by > A custom 2D graphics library > OpenGL ES 1.0 for high performance 3D graphics. • The most common 2D graphics APIs can be found in the drawable package. • OpenGL APIs are available from the Khronos OpenGL ES package, plus some Android OpenGL utilities.
  • 6. What is a Drawable? • A Drawable is a general abstraction for "something that can be drawn." • Drawable class extends to define a variety of specific kinds of drawable graphics, including > BitmapDrawable, ShapeDrawable, PictureDrawable, LayerDrawable, and several more. • You can also extend these to define your own custom Drawable objects that behave in unique ways.
  • 7. Three ways to define & instantiate Drawables • Using an image saved in your project resources • Using an XML file that defines the Drawable properties • Using the normal class constructors.
  • 8. Drawables: Using an image saved in your project resources
  • 9. Creating from Resource Images • A simple way to add graphics by referencing an image file from your project resources. • Supported file types are > PNG (preferred), JPG (acceptable) and GIF (discouraged). • Preferred technique for application icons, logos, or other graphics such as those used in a game • To use an image resource, just add your file to the res/drawable/ directory of your project > From there, you can reference it from your code or your XML layout using a resource ID, which is the file name without the file type extension
  • 10. Build an ImageView that uses an image from drawable resources and add it to the layout LinearLayout mLinearLayout; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a LinearLayout in which to add the ImageView mLinearLayout = new LinearLayout(this); // Instantiate an ImageView and define its properties ImageView i = new ImageView(this); i.setImageResource(R.drawable.my_image); i.setAdjustViewBounds(true); // set the ImageView bounds to match the // Drawable's dimensions i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // Add the ImageView to the layout and set the layout as the content view mLinearLayout.addView(i); setContentView(mLinearLayout); }
  • 11. Handle your image resource as a Drawable object Resources res = mContext.getResources(); Drawable myImage = res.getDrawable(R.drawable.my_image);
  • 12. Add a resource Drawable to an ImageView in the XML layout <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:tint="#55ff0000" android:src="@drawable/my_image"/>
  • 14. Creating from Resource XML • If there is a Drawable object that you'd like to create, which is not initially dependent on variables defined by your application code or user interaction, then defining the Drawable in XML is a good option. • Even if you expect your Drawable to change its properties during the user's experience with your application, you should consider defining the object in XML, as you can always modify properties once it is instantiated.
  • 15. Creating from Resource XML • Once you've defined your Drawable in XML, save the file in the res/drawable/ directory of your project. • Then, retrieve and instantiate the object by calling Resources.getDrawable(), passing it the resource ID of your XML file.
  • 16. XML that defines a TransitionDrawable • Let's assume below is saved as res/drawable/expand_collapse.xml. <transition xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image_expand"> <item android:drawable="@drawable/image_collapse"> </transition>
  • 17. XML that defines a TransitionDrawable Resources res = mContext.getResources(); TransitionDrawable transition = (TransitionDrawable) res.getDrawable(R.drawable.expand_collapse); ImageView image = (ImageView) findViewById(R.id.toggle_image); image.setImageDrawable(transition); The above code will instantiate the TransitionDrawable and set it as the content of an ImageView
  • 19. ShapeDrawable • When you want to dynamically draw some two- dimensional graphics, a ShapeDrawable object will probably suit your needs. • With a ShapeDrawable, you can programmatically draw primitive shapes and style them in any way imaginable.