Android Studio ImageView is not displayed. Determination of the graphic interface

URI images do not display images in ImageView on some Android devices

I have ImageView. When you click on ImageView, it opens the gallery, and you choose the image and show it on ImageView. I have a condition that when I close my application, and then open it, the image will remain there. Therefore, for this I keep URI images on SharedPrefrent. And when opening the application, I get the same URI and tries to display the image on ImageView.

However, in some phones, the image looks perfect like Mi (Lollipop), Samsung (Kitkat) but this is not displayed in phones type-motorola (Marshmallow), One Plus One (Marshmallow). There are ideas why this is happening ? Here is my code

to collect the image that I use

And when extracting from SharedPrefrent, I will convert a line in URI using URI.Parse (Profile_image)

However, if I notice, URI returns for different Android phones as follows

Therefore, when the contents of the URI IS-Content: / / Media / External / Images / Media / IS image display on ImageView is ideal, and in other cases it is not

answers

I have developed and Tested and works for

Now the handle onactivityResult.

Assuming you added Take Permission code to Marshmallow

Lenovo K3 Note: Content: // Com.Android.Externalstorage.Documents/Document/Primary%3adcim%2fcamera%2fimg_20160606_212815.JPG

Samsung: Content: // Com.Android.Providers.Media.Documents/Document/Image%3a2086

Motorola: Content: // Com.Android.Providers.Media.Documents/Document/Image%3a15828

I think that the problem with the URI image file, I use the class to get an accurate URI, and it is tested and works on all versions.

Use getpath to find the exact path to the file. This is a simple way to cope with the problem, as you have determined. Please try and let me know if you need additional help 🙂

‘In previous versions of Android, if you want your application, in order to get a certain type of file from another application, it must cause intention with Action_get_content action. This action is still a suitable way of requesting a file that you want to import in your application. However, Android 4.4 introduces Action_open_Document action that allows the user to select a file of a certain type and provide your application with long.term access to read this file (possibly access to recording) without importing the file into the application.(emphasized)

In order for your application to extract previously selected images, just change the action with Action_get_content to Action_open_Document (the decision confirmed the work on Nexus 7 2013).

Submit your URI in this method, it will return the line and converts it into Bitmap

You need to request permission to read the external storage to the user during execution for Android 6

Perhaps you can cope with this, having first converted URI into a real way.

And your onactivityResult should look like this

I managed to do it in the past. Instead of storing it in Sharepreferences, I keep it in a bag when OnsaveinStancestate (Bundle) is called: Bundle.Putparcelable. You can do this because URI is implemented by Parcelable. After that, check this URI in a package transmitted to Oncreate Code:

P / S: I think the problem of URI storage in Sharepreference is to encode / decoding URI.

You can easily convert URI into Bitmap:

and then install in ImageView: ImgView.SetimagebitMap (images);

there may be a problem with versions of Picasso. They fixed something with the loading of large images in version 2.5.0 (2.four.0. ) who is not yet available through repositories.

You will need to manually turn on the night picture of Picasso, and this will probably correct your problem. For me, yes.

I also ran into something like that earlier and found a useful auxiliary class that gives you an exact location of the file. This is the link.

Animations: Fade Zoom, Rotate to ImageView in Android

You can use methods such as Fileutils.Getpath (context, URI) or Fileutils.Getfile (CONTEXT, URI) to get a file. Then just use it like this:

just not 100% sure if I get a question. If certain images cannot be shown in ImageView (even before closing and restarting the application), then the problem is that Picasso can process the contents from certain suppliers. I do not understand what it is, but if so, then you can consider the possibility of making an error/rfe for this library. On the other hand, if Picasso correctly shows the image for this URI, but not after URI_ORG. String. URI_REGEN transformation then this means that uri_org is not the same as Uri_Rregen. You can (temporarily) add a couple of lines of code to convert the line back to URI and put the stop point immediately after and compare the two URIs. This should give you the key to how everything goes wrong.

If you do not press the stop point, then move the stopping point back to the IF operator and visually check the two URI (which will almost certainly be the same, otherwise you would have a stopping point of the stop, but this will help to check the debugging code itself). If URI is the same, then the lines are not correctly preserved for some reason. In this case, write down the source URI and add a stop point in the line that converts the line back to URI:

If the previous experiment worked, it should work here again if Profile_image does not differ. In any case, you must get signs for where the problem is.

answers

In my case, all my images ImageViews are not displayed when starting my application. The problem is that I am expanding the Activity class from Fragmentactivity. Therefore, I just change his “Fragmentactivity” on “AppCompatactivity”

I had just such a situation. Changing my Activity to AppCompatactivity instead of Fragmentactivity worked perfectly. Also does not affect the functionality.

Where did you put the source file file? This is in the Drawable folder? If so, create MDPI, HDPI, XHDPI, source of the XXHDPI image for image and place them in folders MDPI, HDPI, XHDPI, XXHDPI.

This is the solution that worked for me after checking the XML layout, theme, etc.D. Just changing Extends Activity from your Java class to Extends Appsompatactivity.

If some of the previous proposed solutions have worked for you, others who have the same problem with the image of ImageView, which are not displayed, can also try this.

  • You call SetContentView (for your screensaver) in the flow of a user integer.
  • Are there other actions (or representations) that you show too fast after your screensaver screen (t.e. SetContentView screensavers of the screensaver)?
  • An attempt to use match_parent instead of Wrap_content on ImageView Layut_height and Layout_width.

In what format your drawing file is located? Android prefers to use.PNG mainly.

What is the goal you want to use the image? You want to make a screensaver or another? And mainly the image in PNG Format format.try and check

Image in format.PNG. And yes, this is a screensaver, I just want to display this image in the center of the black screen (when I check the updates from the server, etc. D.)

Is the image a large? Or it should be implemented in your Java file? And if you want to centrize it, you can use Gravity for this.

I had the same problem, and I corrected it, expanding the Appsompatactivity and renaming my image to fix the standard. The name of my image (earlier): Splash-1 (did not work). And I tried to rename the name of the image in Splash1. After that everything worked. Note: The image file can also be responsible for this problem.

Zero bitmap = unsuitable image.

This is the basis of how the image is really used. When the image is used in Android, and it is assigned, it actually converts the image into a raster image, and depending on certain parameters that are the size and various other factors, it may fail, which will lead to the fact that your image will be transformed and will be transformed and will be transformed returned as zero because of a certain mistake that occurred.

Try to make the image size slightly smaller, I think that the Android studio does not support the image with higher pixels. In any case, he solved my problem

Android Studio ImageView is not displayed

In the last topic, it was considered how to display images using the ImageView element. Now consider some additional points to work with this element.

Some main attributes of the ImageView element:

Android: Croptopadding: at the value of TRUE, the image is cut in accordance with the established retreats

Android: Scaletype: sets how the image will be scale relative to the boundaries of the ImageView element

To set the scaling parameters, one of the values ​​of the listing is used:

Center: The image is centered in the center without scaling

Center_Crop: The image is centered in the center and scaled with the preservation of the aspect relationship between the width and height. If some part is not placed within the screen, then it is cut

Center_inside: The image is centered in the center and is scaled with the preservation of the aspect relationship between the width and height, but the width and height cannot be greater than the width and height of ImageView

Fit_Center: The image is scaled and centered

Fit_Start: The image is scale and is installed at the beginning of the element (up with portrait orientation and to the left. with album)

Fit_end: the image is scale and is installed at the end of the element (down with portrait orientation and right. with album)

Fit_XY: The image is scaled without preserving the aspect relationship of the Mezhud width and height, filling the entire ImageView space

MATRIX: The image is scaled using an image matrix

Android: alpha: sets transparency (value from 0.0. completely transparent to 1.0. completely apparently)

Android: tint: the color used to apply to the image

Android: tintmode: mode that is used to apply color on the image

Some main methods of the ImageView class:

Drawable Getdrawable: Returns Drawable Resource. which is associated with the data of ImageView (or Null. if the resource for ImageView is not set)

ImageView.Scaletype Getscaletype: returns the value of the ImageView list.Scaletype, which indicates how the image is scaled relative to the boundaries of the ImageView element

VOID Setimageedrawable (Drawable Drawable): sets the image resource using the Drawable object

VOID SetimageSource (Intsid): sets the image resource using the DRAWABLE resource identifier

VOID Setimageuri (URI URI): sets the image resource using the URI address of this resource

VOID Setscaletype (ImageView.Scaletype Scaletype): sets the scaling of the image

VOID Setimagealpha (int alpha): sets image transparency. value from 0.0 to 1.0

For example, setting Fit_XY values ​​for the Android attribute: Scaletype in the Activity_Main file.XML:

The image is shown in Android Studio, but not on the phone

As you can see below, it shows Android Studio:

However, when I launch this application on my phone, viewing the list shows only an empty image (t.e. gap) above him, where it should be “somewhere above the rainbow”.

View mode works great. It consists of one image and two text representations. (This image of the image works if it helps). If something of this may intervene, I will send the code here, but it is difficult for me to believe.

The only thing I did not know about. This is a relative form when determining cells to present a list in a separate XML file. I don’t understand why not, but this is the only thing I might have thought about.

Android : Android ImageView Is Not Displaying Image?

Basically, the Android studio shows everything that works, but on the phone/emulator this is not so. Therefore, it is very difficult for me to find a problem.

I am a beginner in the Android development script, so it’s easy for me.

The image has a format.png and is in the folder with the possibility of moving. I also have another.PNG Image in a folder with the possibility of transfer, which, it seems, does not cause problems. Why is it so? The original image is clearly not damaged, since it is displayed in Android Studio

When moving the image to the “Mipmap-XXHDPI” folder due to size

The image should be displayed regardless of your folders. There may be some other problem. Please provide more information or publish your code.

“The image should be displayed regardless of your drawing folders,” this simply does not correspond to reality. I carefully tested it, and he simply will not be displayed (say, in a “note”), if he “goes beyond the size” or if he is “drawn” and he is very large. The use of “DRAWABLE-NODPI” seems to make it work as in ordinary operating systems. It actually draws.

answers

Today I have found the same problem. Therefore, first check the height and width of the image and on the basis of this place the image in another folder. I.E if the image size is 1280 x 840, than put the image in the DRAWABLE-XXHDPI folder.

If your image is too large, use a universal image bootloader or salvo for quick loading of the image

I came across the same problem and found the answer below: (

What I did to make him work. Change the assigned automatic key (filled using DRAG/Drop ImageView) with App: srccompat = “@dRavable/logo” to Android: SRC = “@Drawable/Logo” on the Text tab so that it displays both on the emulator and On the device, for example

I recently had the same question if you can check in which folder it is located. For me, the problem was to place it in a folder with the possibility of transfer, while it should be DRAWABLE-NODPI

Also indicate which device you see this problem, these are several devices?

Thanks for the quick response. The image is really in the Drawable folder. This is PNG format. I also have another image in the Drawable folder, also in PNG format. However, this one seems to work. So the problem should be in the image. But how it makes sense?

I had the same, only one image did not work. Could you try to rename the folder in Drawable-Nodpi. I must say, I really don’t know why it worked, but it worked.

Just select the folder, make Shift F6, Android Studio will fix links for you, it can even do it without refactory. (Always use Shift F6 when you rename classes or variables;))

I can confirm that the placement of large images in a higher HDPI folder operates on Samsung Galaxy S4 when viewing images.

The problem was that an affordable folder for a higher HDPI did not exist. But if you create a new folder and name it Drawable-XXHDPI or DRAWABLE- (WhatverxXXHDPI). Place it in [Path to Your Project Folder] \ App \ SRC \ Main \ Res \. Then place your image there, it should work.

If you use Android: SRC or App: SRCCOMPAT instead of Android: Background:

An earlier duplicated question was asked (I have not enough points to put the flag above like a duplicate) here, and the proposal of Lukap about the Drawable-Hdpi folder worked for me. Apparently, the use of standard three folders (-HDPI.MDPI.LDPI) was a standard practice.

The image of the image in any of the mipmap folders also worked for me (and then, of course, changing Android: SRC = “https: // Overcoder.Net/Q/1336105/@DRAWABLE/IMAGE “on Android: SRC =” https: // Overcoder.NET/Q/1336105/@mipmap/iMage), Android developer page for applications says that MIPMAP resources are designed for “hard files for different sizes of the launchers”. Thus, the placement of images other than the launch badges in the Mipmap folder seems to work, but does not comply with Android agreements.

It seems to me that an error for the image is not displayed when in the only available available folder/folder, since others recommend using an outgoing folder for all images that are not applications icons. On the page “Android Developer” for “providing resources” there is a section that discusses an approach that Android uses to select the best suitable resources using an example in which available resources are somewhat available.

To demonstrate how Android chooses an alternative resource, suppose that the following available catalogs contain different versions of the same images:

hood/ draw/ draw/ draw-fry/ draw/ draw-port/ draw-an-notouch-12key/ draw-port-ldpi/ drawable-port-notouch-12key/

And suppose the device is configuration:

Local = EN-GB screen orientation = port the density of the screen pixels = hdpi touch screen = notouch method of entering the main text = 12key

Comparing the configuration of the device with an affordable alternative to resources, Android selects drawings from DRAWAWABLE-EN-PORT.

If there is only one folder with the possibility of cutting/choosing, you might think that the “logic” of the Android will choose the only available resource that can be used.

How to combine delegates

Combine all supported delegates in one place and reduce the interaction interaction interaction to the Displayto method.

I pay attention to line 18. Using the FIRST method, we find the first suitable delegate to display the picture. If the desired delegate is not found, the crash is possible, and this is not a design error. We deliberately adhere to the principle of Fail-Fast in order to quickly get rid of unobvious behavior. For example, when the picture was not displayed, and we do not know the reason.

How to launch transformations

Let’s figure out why the display of transactions may need transformations. Suppose we have an avatar of contact or seller that we receive from the network. It can have any shape and size, but in the Revolut application, we must display it round and a certain size. 40×40 dp.

Set the model and achieve this behavior.

Take a URLIMAGE. Any picture that needs to support transformations should have appropriate settings. You can enter the Transformableimage Inte Week with the property of Transformations:

To display pictures we use glide. Accordingly, transformations are oriented to this library.

This is how the converting array is created. I will note two points that will help to avoid extra work.

Firstly, the fields are marked as nullable, and this allows you to set only the necessary transformations. Secondly, not obvious, but critical in what order the transformations will be caused.

Imagine that at the entrance there is a very wide picture that must be turned, replaced and twisted. Compare the two scenarios of the development of events.

In the first case, at first we turn the picture 90 degrees, then rounded and only after that we change the width. In the second case, we first change the width.

The second scenario is more effective, since the turn and rounding of “cheaper” do in smaller images.

Let’s get back to the implementation. Previously, we created an array that should now be transferred to Glide when it will display the picture by URL. We create an object of RequestoPTIONS and hand over an array to it. Remember that you can not transmit an empty array. Glide will fall. Therefore, be sure to add a check.

Since we will redesign transformations in different delegates, it will be convenient to bring them to the Applyimagetransformation extensive.

Also add the method to the Transformableimage Inte Wee. Getglidetransformsarray. The Applyimagetransformations integration and extensive integration and extensions are marked as internal. So we avoid abstraction leakage, and the final user of models and delegates does not know what is used inside. Glide is not visible in public intenses. Convenient if we want to replace Glide with another library.

As a result, the code is reduced to this type:

Mainactivity software module

After the application integration is determined, you need to connect the appropriate events to the buttons buttons. To do this, open the Mainactivity module in editing mode and make the following changes:

  • We determine the integer variable Imageidx used to index the images of estates;
  • We create a Getimageid method that returns the identifier of the graphic image resource depending on the current Imageidx value;
  • Create the Changeimage method displaying the current graphic image;
  • We connect events to the buttons buttons. When you press the button, the value of the current Imageidx identifier is changed, and after that the Changeimage method is called.

I believe that the Mainactivity module code is trivial and does not require special Комментарии и мнения владельцев.

After the start of the application, you should see the following integer:

The source code of the example is not given, everything is described in detail. Therefore, you should not have difficulty repeat this example yourself.

The use of the background image in the marking of the android activity intensity of the application is presented here.

Using images/icons in the Android menu is presented here.

Work with images

One of the most common sources of resources is image files. Android supports the following file formats:.PNG (preferred).JPG (acceptable).GIF (undesirable). For graphic files in the project, the Res/Drawable folder has already been created by default. By default, it already contains a number of files. A couple of icon files:

When graphic files are added to this folder for each of them, Android creates a DRAWABLE resource. After that, we can turn to the resource as follows in the Java code:

For example, add to the project to the Res/Drawable folder some image file. To do this, we copy on a hard drive some file with an extension of PNG or JPG and insert it into the Res/Drawable folder (for copying into the project, simple Copy-Paste is used)

Next, we will be invited to choose a folder. Drawable or Drawable-24. To add ordinary images, select DRAWABLE:

Here it is immediately worth considering that the image file will be added to the application, thereby increasing its size. In addition, large images adversely affect performance. Therefore, it is better to use small and optimized (compressed) graphic files. Although, it is also worth noting that all the image files that are added to this folder can automatically be optimized using the Aapt utility while building a project. This allows you to reduce the file size without loss of quality.

When copying the file, we will be invited to install a new name for him.

You can change the name of the file, or you can leave it as there is. In my case, the file is called dubi2.PNG. And then click on the Reatactor button. And after that, the image file selected by us will be added to the Drawable folder.

To work with images in Android, you can use various elements, but ImageView is intended directly to output images. Therefore, change the Activity_Main file.XML as follows:

In this case, to display the file in ImageView, the element has an android attribute: SRC. Its meaning indicates the name of the graphic resource, which coincides with the name of the file without expansion. And after that, already in Preview or in the designer mode in Android Studio, you can see the application of the image, or when starting the application:

If we created ImageView in the Java code and from the code would use a resource, then Activity could have looked like this:

In this case, the Drawable resource is directly transmitted to the ImageView method.SetimageSource. and in this way the image is established. As a result, we get the same result.

However, it may need to somehow process the resource before use or use it in other scenarios. In this case, we can first get it as an object of Drawable and then use it for our tasks:

To obtain the resource, the ResourcesCompat method is used.Getdrawable. to which the Resources object is transmitted, resource identifier and topic. In this case, the topic is not important to us, so for it we convey the value of NULL. The resource returns in the form of the Drawable object:

Then, for example, you can also transfer the resource to the ImageView object through its SETIMAGEDRAWABLE method

  • File New Project Empty Activity
  • NAME: AndroidimageView
  • Package Name: Org.O7Planning.AndroidimageView
  • Language: Java

If you are interested in simple steps in the design of the integration of this application, see the application at the end of this article.

You can also get the image from the URL on ImageView. The rule you need to download the election from the URL then display on ImageView:

Obtaining data from the URL is associated with the programming of the network in Android, you can find an example of displaying the image taken from the URL on ImageView in the article of the Android network programming instructions for this link:

Russian blogs

When I wrote the code today, I found that ImageView uses SRC to set the image so that it is not displayed on some phones. Below is my code:

It doesn’t matter how you look at this code, this is normal, so I changed the image and found that it could be displayed normally, and then found that this is a problem with the image.

When I opened the properties of the image, I found that the image is huge, 200k. Thus, it can be displayed normally after its compression (I squeezed it three or four times until it can be compressed, and the image is compressed to about 20 kb). Here is a very useful website for image compression:

Imports Pycharm Import works tips on annotation

Pycharm has a red error when importing a user module, but the time is normal, show an error message: No Module Named Test1 Less. (Ctrlf1) Inspection Info: this in.

The line contains n characters where there are M different characters, n m, find the smallest time and space to find the shortest line containing all M-symbols, do not consider special characters.