Questions tagged [android-imageview]

Displays an arbitrary image or a drawable, such as an icon or an xml defined graphical element.

Displays an arbitrary image, such as an icon. The ImageView class can load images from various sources (such as resources or content providers) and it will take care of computing its measurement from the image so that it can be used in any layout manager. It also provides various display options such as scaling and tinting.

More information can be found in the documentation for the ImageView class.

4273 questions
1185
votes
37 answers

findViewById in Fragment

I am trying to create an ImageView in a Fragment which will refer to the ImageView element which I have created in the XML for the Fragment. However, the findViewById method only works if I extend an Activity class. Is there anyway of which I can…
simplified.
  • 11,977
  • 5
  • 17
  • 8
704
votes
58 answers

How to make an ImageView with rounded corners?

In Android, an ImageView is a rectangle by default. How can I make it a rounded rectangle (clip off all 4 corners of my Bitmap to be rounded rectangles) in the ImageView? Note that from 2021 onwards, simply use ShapeableImageView
michael
  • 106,540
  • 116
  • 246
  • 346
591
votes
26 answers

How to scale an Image in ImageView to keep the aspect ratio

In Android, I defined an ImageView's layout_width to be fill_parent (which takes up the full width of the phone). If the image I put to ImageView is bigger than the layout_width, Android will scale it, right? But what about the height? When Android…
michael
  • 106,540
  • 116
  • 246
  • 346
348
votes
15 answers

Show Image View from file path?

I need to show an image by using the file name only, not from the resource id. ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.img1); I have the image img1 in the drawable folder. I wish to show that image from the…
Alex
  • 16,375
  • 7
  • 22
  • 19
324
votes
8 answers

Changing ImageView source

I have an ImageView with a source image set in the xml using the following syntax: Now I need to change this image…
nourdine
  • 7,407
  • 10
  • 46
  • 58
308
votes
18 answers

How to clear an ImageView in Android?

I am reusing ImageViews for my displays, but at some point I don't have values to put it. So how to clear an ImageView in Android? I've tried: mPhotoView.invalidate(); mPhotoView.setImageBitmap(null); None of them have cleared the view, it still…
Pentium10
  • 204,586
  • 122
  • 423
  • 502
256
votes
1 answer

How to create a circular ImageView in Android?

How could I create a rounded ImageView in Android? I have tried the following code, but it's not working fine. Code: Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); BitmapShader shader =…
user2134412
245
votes
9 answers

'Missing contentDescription attribute on image' in XML

I get an warning about [Accessibility]Missing contentDescription attribute on image in eclipse. This warning show at line 5 (declare ImageView) in XML code below. This not make any error when build and run my application. But I really want to know…
PhatHV
  • 8,010
  • 6
  • 31
  • 40
185
votes
6 answers

Difference between app:srcCompat and android:src in Android's layout XML

Whenever I create an ImageView with icon added using Android Studio's Vector Assets, I'm getting an error at the line app:srcCompat="@drawable/ic_play" When I change the app:srcCompat with android:src, the error is gone but the icon looks pixelated.…
Zayid Mohammed
  • 2,275
  • 2
  • 10
  • 17
174
votes
16 answers

How to set a ripple effect on textview or imageview on Android?

I want to set a ripple effect on textview and imageview in Android Studio. How can I do it?
Vasant
  • 3,475
  • 3
  • 19
  • 33
170
votes
3 answers

What's the difference between CENTER_INSIDE and FIT_CENTER scale types?

I can't tell the difference between ImageView.ScaleType.CENTER_INSIDE and ImageView.ScaleType.FIT_CENTER. CENTER_INSIDE Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be…
Keith
  • 2,958
  • 4
  • 26
  • 29
161
votes
4 answers

Difference between a clickable ImageView and ImageButton

I'm just wondering if there is any significant difference between an ImageView that's set to be clickable, compared with an ImageButton? Is there any reason for using one over the other? Is there any restriction on the drawable for an ImageButton…
yjw
  • 3,394
  • 4
  • 20
  • 20
159
votes
4 answers

How can I change the image of an ImageView?

I have just started learning android. And i don't know How can I change the image of an ImageView? ie it has some Image which was set in the layout but i want to change that image through coding how should i do it ? Here is the xml…
BBdev
  • 4,898
  • 2
  • 31
  • 45
159
votes
18 answers

"Bitmap too large to be uploaded into a texture"

I'm loading a bitmap into an ImageView, and seeing this error. I gather this limit relates to a size limit for OpenGL hardware textures (2048x2048). The image I need to load is a pinch-zoom image of about 4,000 pixels high. I've tried turning off…
Ollie C
  • 28,313
  • 34
  • 134
  • 217
151
votes
10 answers

Android and setting alpha for (image) view alpha

Is there really no XML attribute counterpart to setAlpha(int)? If not, what alternatives are there?
Ken
  • 30,811
  • 34
  • 116
  • 155
1
2 3
99 100