Digvesh Patel
Digvesh Patel

Reputation: 6533

Diffrence beetween Imageview and Imagebutton respect to memory occupy by OS

I have recently notice in one of my project that on some layout i define ImageButton and on some layout i define ImageView.

both are working fine with same role and same task.

but,

my question is; is there proper way ? and if not than what is main diffrence beetween tham. And also let me know any memory related diffrence for define imageview and imagebutton?

Which component occupy more memory on running.

Thanks in advance.

Upvotes: 1

Views: 131

Answers (2)

Suhail Mehta
Suhail Mehta

Reputation: 5542

ImageView extends View

where as

ImageButton extends ImageView.

ImageView is used set icons from different sources where as ImageButton ,displays a button with an image (instead of text) that can be pressed or clicked by the user .

Memory allocation of both the views depends on the image src else there is not significance difference in terms of memory .

Upvotes: 2

laalto
laalto

Reputation: 152857

ImageButton is-a ImageView which essentially just supplies a default style for the image button, and the image button default style supplies a button background drawable.

With everything else held constant, changing an ImageView without a background to an ImageButton consumes more memory since the background takes up some. If you're concerned, use a memory analysis tool to find out whether the difference is significant.

Which one to use: Use ImageButton if you want an ImageView with button styling. If you just want to display an image, use ImageView.

Upvotes: 3

Related Questions