I am trying to add an image slide on my android app.
When I try to add the source for the image, from drawable folder, I can't select the iamges.
Here, a little screenshot to understand better the problem:
Screen
What can I do to solve it?
Thank you for your answer.
the naming convention shouldn't be a number. declare it in small letters, like this -> image_one ......e.tc.
You should use PNG or WEBP images as your drawables.
As you may already know variable names should not start with a number. So in your case using a number as your image name forces the compiler to generate a variable named as your drawable name which cannot be accepted in programming, hence the constant R.drawable.1 does not get generated. Try renaming your drawable to an alphabetical equivalent.
Related
I have a lot of images and I want to classify them in the drawable folder in Android Studio for easy access, is it possible?
Not possible. The only way to sort your drawable resources is by renaming them, usually with prefixes (i.e. ic_ for icons).
You can't put them in folders. However, you can control the name of them to find them easier. For example, if I have buttons coded with shapes, etc, I will name these button_name. This way, it all of my buttons are there for me to view. If I have a few minutes in a certain activity, I will do something like results_, and then all of my results images are there. Hopefully they makes sense and helps.
My ImageButton in my app is very tiny and cut off. I realized this could be because the image was in the drawable folder instead of the mitmap folders. So, I copied the images from the drawable folder, and pasted them in mitmap folders. Now, should I go about deleting the image from the drawable folder? I get the following saying it is not safe:
I know how to access the images, but should I delete them from the drawable folder now that I have already moved them to the mitmaps? If I do a delete anyway, will I need to alter my code to access the mitmap image? What is safest to do?
Here is an image of my mitmaps:
Thanks for the expert advice,
Rich
"Not safe" in this context just means that it's still being used somewhere. If you delete it, the current usage will fail to compile, and you'll be easily able to find and alter it to point at the new location.
You can safely delete this image, in Android Studio if you are using this image or else the file will be open at some place, you can get this error actually, so try deleting this image will safely remove the only selected image into your workspace. So hassle free to delete it.
After deleting your image, clear your project and run it, it works fine.
The mipmap folder is used for image that are very small and should be used in the action bar, and other menus. If you find your image too tiny, it just will be worst if you put it in the mipmap folder. If it's tiny although the image is in the drawable folder, maybe the image has a very small dimension or your imageview is too small.
Sometimes when I put images in my "drawable" folder, the image name is red. Doing right-click->Synchronize doesn't seem to help at all, and they crash my app when I try to use them in an activity. What does it mean and what should I do to fix this?
EDIT: It says "out of memory error." I think the image is too big, actually, not to do with teh red thing.
It means those files are untracked by git. You may want to add them to your git repo (this will make them green)
But.. they won't crash your application.. there's something else going on then
Means your project is connected to git and you can push edits to make it green, or just ignore that!
and they crash my app when I try to use them in an activity.
May that happen because you name images in uppercase or their name contains special characters, it's must be in lowercase and no symbols.
EDIT:
It's crashes because it's a big images, just use small images because you deal with piece of limited resources, and it will be great if it a PNG.
Sometimes When the file name starts with a Capital letter a red underline is shown.
I'm implementing a code-snipped in my android application, where i open a popup window. This popup window takes a little drawable and put it around itself. This png resource is named *.9.png. I can rename it as i prefer, but if i remove the 9 the output of the resource is different. With the number the png is displayed correctly; otherwise it is stretched on the entire window.
What does it mean? Does the framework do something special seeing this number. Moreover i noticed that that when this resourced is used in code or XML, the .9 has to be omitted...so i think that it is for the framework.
Could someone explain it in detail?
The code comes from the QuickAction3D package.
Yes, a *.9.png naming indicates a Nine-patch image, which is an image with annotations to modify stretching behaviour.
How to pick image from particular folder, say sdcard/mypics?
i can recommend the gridview tutorial.
you will have to modify the code a bit to get the resource into an array before showing the gridview. but therefore you can use the BitmapFactory class.