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
51
votes
4 answers

How to stretch three images across the screen preserving aspect ratio?

I need to display three same size images (200 X 100) side by side (no gaps) on top of the screen. They should occupy entire width of the screen and preserve aspect ratio. Is it possible to accomplish that using only layout xml file, or I need to…
Peter
  • 511
  • 1
  • 5
  • 3
50
votes
7 answers

How to change ImageView source in android

This is my xml, this is located inside a fragment that appears in my activity.
jofftiquez
  • 7,548
  • 10
  • 67
  • 121
49
votes
7 answers

ImageView fills parent's width OR height, but maintains aspect ratio

I have a square image (though this problem also applies to rectangular images). I want to display the image as large as possible, stretching them if necessary, to fill their parents, while still maintaining the aspect ratio. The image is smaller…
48
votes
2 answers

ImageView not keeping max height and width

I load an image into an ImageView using .setImageURI(selectedImageUri) that is retrieved from the user's photo gallery. I have the image view restrict the size with android:maxHeight="150dp" android:minHeight="150dp" android:maxWidth="150dp"…
bwoogie
  • 4,339
  • 12
  • 39
  • 72
48
votes
6 answers

implement android:src="@drawable/image" programmatically in Android

I am trying to set the foreground image on an image button. After some research, I came across this code sample:
user788511
  • 1,726
  • 2
  • 30
  • 52
45
votes
7 answers

How to apply shadow to ImageView?

I want to apply shadow to the ImageView. When I'm applying shadow to a TextView I'm getting it but same it's not getting to ImageView. How can I solve this problem?
45
votes
7 answers

Setting of ImageView's gravity to the center in android programmatically

I want to set the gravity of an array of Imageviews,ImageIcons[i] to the center with the following code, ImageIcons[i] = new ImageView(this); ImageIcons[i].setLayoutParams(new…
Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40
45
votes
2 answers

Android layout - alignment issue with ImageView

I'm trying to put an image at the top left of a LinearLayout, but with the image border and padding taking up the whole of the width of the window. If I try the XML below, I get my image with its border and a white background across the whole width…
Alnitak
  • 334,560
  • 70
  • 407
  • 495
44
votes
1 answer

Byte array of image into imageview

I've searched a bit but can't get a clear glimpse of it. How can I set a byte array of an Image into an ImageView? I tried with this but it didn't work. BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
Manoj Kumar
  • 1,510
  • 3
  • 20
  • 40
42
votes
6 answers

How to use selector to tint ImageView?

I want to tint my tabhost's icons using XML, instead of doing it programmatically (I wasn't able to do that anyway)... I found this thread on SO: Android imageview change tint to simulate button click That seems to be a pretty good solution, but I…
Lucas Jota
  • 1,863
  • 4
  • 24
  • 43
42
votes
4 answers

Applying ColorFilter to ImageView with ShapedDrawable

I have an ImageView with android:src set to a ShapedDrawable, namely a white circle. What I want is to colorize this ImageView in runtime responding to some events. imgView.setColorFilter seems to be solution, but after using this (tried different…
aplavin
  • 2,199
  • 5
  • 32
  • 53
41
votes
5 answers

ImageView adjustViewBounds not working

I have an ImageView with android:layout_width=100dp, android:layout_height=wrap_content and android:adjustViewBounds=true It's source is a 50 x 50 px picture. But the aspect ratio is not preserved - height of the ImageView is 50px, not 100px (i.e.…
fhucho
  • 34,062
  • 40
  • 136
  • 186
41
votes
5 answers

How can i get center x,y of my view in android?

I am attaching an imageview up on my frame layout. Here i want to get my imageview center co-ordinates. i will use that same co-ordinates to set my imageview in next layout. Please suggest me how to get the center co-ordinates of my…
Raghu Mudem
  • 6,793
  • 13
  • 48
  • 69
40
votes
3 answers

Controlling view visibility from a resources

I have a layout that contains two ImageViews. I want one of them to be visible in portrait and the other in landscape. How do I achieve it using resources? (I know how to set it programmatically for but this specific use I need to achieve it using…
user1139880
  • 1,828
  • 3
  • 18
  • 27