I have a really annoying bug that has crept into my android app and I can't locate the cause (although it is possibly because I upgraded to SDK 23).
I am dynamically referencing a series of ImageView elements and filling the ImageView with a bitmap:
ImageView img = (ImageView) activity.findViewById(context.getResources().getIdentifier(result.getView(), "id", context.getString(R.string.packagename)));
img.setImageBitmap(bitmap);
All of the ImageViews were filling correctly and now just one of the images is not filling (but the others are)
I suspect that the image is filling but is subsequently being either overwritten, hidden, sent to back or something else.
I have tried the debugger in Android studio that appears to confirm the ImageView is being correctly referenced and there is an image in 'bitmap' but what I can't seem to do is find if it is subsequently changed
Question
Is there a way to set a debugging 'trap' to catch whenever a Resource ID is accessed (i.e. I want to know when there are changes to my R.id.inv_image
Thanks for suggestions and have now resolved problem - may be helpful to someone in the future!
I had an ImageView with and xml setting:
android:layout_height="400dp"
android:layout_alignBottom="#+id/value_title"
So this anchored the base of the ImageView and the 400dp height was bigger than the available space on the display (?? ImageView was sticking out of the top but truncated??)
I believe that prior to sdk 23 the bitmap I put in the box was bottom aligned and I could see it without problem as the height of the bitmap was about half the ImageView height and filled the visible ImageView perfectly.
From sdk 23 it seems the bitmap is top aligned and so the image was invisible as the bitmap was placed above the viewable region, and all I could see was the blank bottom of the ImageView.
Fixed it by reducing the height of ImageView:
android:layout_height="106dp"
Related
I'm using Android Studio, and have created an ImageView in activity_mail.xml. The layout width and height are set to "match_parent". The scaleType is set to "center" and the source image is 70x70 pixels. When I run the app in the emulator the Image appears on the screen larger than 70x70 pixels. I mean it takes up more than 70x70 pixels on the screen of the phone. I don't know why it's doing this. The app is exclusively in Landscape mode, that might be relevant. Forgive me if I have included extraneous details, I genuinely don't know what information would be relevant to include. I intend to make it so that the image takes up 70x70 pixels on the screen of the phone. What is causing the unintended result, and how could I fix it?
change ScaleType, maybe fit_center instead of just center + android:adjustViewBounds="true” will fit your purposes... another way is to create ImageView with wrap_content sizes placed in some container (e.g. RelativeLayout) with match_parent sizes
also check this visual guide for ScaleType
note that 70px image will be big on devices with HD resolution and significantly smaller on those with e.g. full HD. you should have few versions of your image in proper density buckets (mdpi, hdpi etc.) or just download proper size if your image comes frome some API, so then you can say that you have image with 70dp dimension, not 70px
I have a list which contains posts that each contain one image. The ImageView width is set to match_parent, so it's always the same. Thee ImageView height is set to wrap_content, so the image height is not always the same. The last thing is what causes a problem with scrolling, because I'm also using Glide. The system doesn't know how far it has to scroll until Glide loads the picture, gets the dimensions of it and then resizes the ImageView. When the picture is done loading and the ImageView height is set, the list "jumps" and the screen shows another post. This is solved when wrap_content is replaced by a fixed value, but this is not what I want, because in that case there's a lot of empty space around the picture for some images.
Is there any other way to achieve what I want?
Edit: the solution works, but it was still not what we wanted to achieve. We ended up changing the JSON. It now shows a ratio as well, with which the size of the ImageView can be calculated before the picture is loaded. This way the ImageView has a fixed size anyway, but it's an individual fixed size.
Check out Glide.with.pauseRequests:
if you call Glide.with(fragment/activity).pauseRequests(), new
requests will not run until you make a corresponding resumeRequests()
call. Those changes let you add an OnScrollListener and pause/resume
requests depending on the scroll state.
I'm trying to take a screenshot with Robot and view it in an ImageView, The problem is the screenshot coordinates is the ImageView Global coordinates.
So basically I'm trying to capture what's behind the Imageview but instead I get a picture of the Imageview itself.
I can't minimize because I'm taking several continuous screenshots that may vary in resolution.
What can I do?
I'm new to Android Java programming. For a project I need transparent images, which change dynamically. I have created a layout with an ImageView. And in it a small GIF USA flag GIF with a transparent background.
In code I connect the variable to the imageview and assign the same image to the variable from the ImageResources
ImageView image = (ImageView)convertView.findViewById(R.id.listview_image);
image.setImageResource(R.drawable.vlag);
This goes pretty well however the image is displayed with a white background. The transparency is lost. This is shown in the image below by the white background.
GIF over ImageView are always an issue. Use GIFImageView
And you must use it this way:
gifImageView = (GifImageView) findViewById(R.id.gifImageView);
gifImageView.setBytes(bytes);
gifImageView.startAnimation();
Even it has an option to download the gif from the web.
I have an imageview that displays a photo taken with the phone's camera, which can be changed by the user. The problem I'm having is that the picture is scaling too small within the imageview, is there a way to force the bitmap to fit the imageview completely?
Next time, please search a few minutes, before you ask a question!
In the layout xml-file you have to add the following attributes to your ImageView to make it fill out the view:
android:scaleType="fitCenter"
You can find the attribute in the ImageView documentation's list of XML Attributes. The different scaleTypes can then be found by clicking "android:scaleType" to get to its description.