Difference between a clickable ImageView and ImageButton

ImageButton has a non-null background by default.

ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it’s always inflated as focusable.

Here’s ImageButton‘s default style:

 <style name="Widget.ImageButton">
     <item name="android:focusable">true</item>
     <item name="android:clickable">true</item>
     <item name="android:scaleType">center</item>
     <item name="android:background">@android:drawable/btn_default</item>

使用XML为ImageButton 做图片切换的交互

Change ImageView size programmatically

The image on the surface of the button is defined either by the android:srcattribute in the XML element or by the setImageResource(int) method.

android:padding setPaddingRelative(int,int,int,int) Sets the padding, in pixels, of all four edges.
android:maxHeight setMaxHeight(int) An optional argument to supply a maximum height for this view.
android:maxWidth setMaxWidth(int) An optional argument to supply a maximum width for this view.

What is the difference between dip,sp and px in android?

Lower resolution screen Higher resolution, same size
Physical Width 1.5 inches 1.5 inches
Dots Per Inch (“dpi”) 160 240
Pixels (=width*dpi) 240 360
Density (factor of baseline 160) 1.0 1.5
Density-independent Pixels (“dip” or “dp” or “dps”) 240 240
Scale-independent pixels (“sip” or “sp”) Depends on user font size settings same

Notes: Density does not exactly follow the real screen size, pixels are not necessarily squares, there is no strict definition for what a “pixel” means. This may be confusing but not as much as CSS Units (em, ex, pt, etcetera).

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

set your required image in the imageview and use an onclicklistener to detect clicks like you would do for an ImageButton.

specify the width of your ImageButton and set the padding as required (this is if you want to use android:background=”#00000000″).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s




Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......







Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: