I've made a few shapes in drawable folder, is it possible to packed them in one resource file? How?
u can take indivitual images and place them one after the other with the
android:layout_x="0px"
android:layout_y="6px" parameters..
but it is not possible by default in android
Actually it is possible, by using level-list XML element.
If you look at this post it shows you how to do it.
You can even define the drawable within the level-list
Related
Let say i want these shapes in my project, like rectangle, ring and oval:
Which means i should have three xml files for each shape.
So, as far as i know we create separate xml file for each shape. Is this mandatory to create each shape in separate xml file? Is there any way to create all needed shapes in one xml file and call each shape with the help of attribute name, id or something else which will help us to reduce the number of xml files?
To give you an answer : no, you have to have different files.
But there are several different advantages to this : having 3 different files means that they are easier to re-use (in future, you can select to add ONE file to your new project and skip the others) and it's easier to modify (finding ONE file to edit is simpler than having to scroll through ,which could at that point be, 1000 shapes). Even though this is potentially debatable and having one file also has its own advantages, the answer is still : you have to create separate files
It's not possible. You can't reference them from code any more.
How to set image from android drawables at ImageView?
Not from R.drawable but from defaults... I.E. a star.
I know how to do it in xml, now I want to do the same from Java.
If by defaults you mean drawables that are bundled with android you set them in the same way as normal drawable eg imageView.setImageResource(android.R.drawable.stat_notify_sync), you just prefix R with android
First of all, to work with images at the Android environment, you have to put the images in the drawable directory, and the only way to use them in your application is using the class R. The example to set a image on android programmatically in Java is below:
YourImageView.setImageResource(R.drawable.name_of_your_image);
I see in the documentation here https://developer.android.com/guide/topics/resources/drawable-resource.html, that all types of drawable resources are located under .../res/drawable.
Neither drawable resource is under .../res/mipmap-*.
So, does this mean that .../res/mipmap-* doesn't contain any drawables? If I create image file, scale it to various sizes and put into .../res/mipmap-*, the same way as ic_launcher lays, will I be able to refer this resource from XMLs as drawable?
So, does this mean that .../res/mipmap-* doesn't contain any drawables?
It contains bitmaps, mostly of launcher icons.
will I be able to refer this resource from XMLs as drawable?
No, but you will be able to refer to that resource as a mipmap (#mipmap/ic_launcher), the same way that you see in the manifest for launcher icons.
All,
I'm trying to dynamically change the image displayed on the thumb of the seekbar in java, and came across the setThumb method. I have a .png file under res/drawable, but can't find the right way to refer to that .png file using setThumb(). Do any of you know how to do it?
Best and Thanks in Advance!
You need to create a drawable from your resource.
Drawable mypicture= getResources().getDrawable(R.drawable.mypicture);
I want to set a specific background image for all my buttons.
So, I changed my PNG file into a Ninepatch drawable using the "draw9patch" tool(by specifying the line of strecth).
Then, I applied this as background to my button using
"myBtn.setBackgroundResource(R.drawable.new_png);"
Now, the background appears for the button, but the lines of stretch are also visible on the android screen, wherever I'd specified them in the tool.
Can you help? Is there something wrong in how I'm using the tool?
Ninepatch png files must be named with a special naming convention: for instance in your example, new_png.9.png. When you refer to the drawable in your code, you exclude the '.9.png', so your code would not need to change, only the image file name needs to change.