Android :: Setting An Image View Resource As Drawable
May 2, 2010
I am trying to create a drawable in code and change the color based on some criteria. When I try and set the Drawable as the background of the ImageView it displays but won't let me set any padding. I realized I need to set the ImageView image via the setImageDrawable() function in order to be able to set the padding. The problem I am running into is that when I set it via the setImageDrawable() function nothing is displayed.
Here is what I have written:
<?xml version="1.0" encoding="utf-8"?>
ImageView icon = (ImageView) row.findViewById(R.id.icon);
ShapeDrawable mDrawable; int x = 0; int y = 0;
int width = 50; int height = 50;
float[] outerR = new float[] { 12, 12, 12, 12, 12, 12, 12, 12 };
mDrawable = new ShapeDrawable(new RoundRectShape(outerR, null, null));
mDrawable.setBounds(x, y+height, x + width, y);
switch(position){ case 0: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 1: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 2: mDrawable.getPaint().setColor(0xff00c000); //Green break;
case 3: mDrawable.getPaint().setColor(0xff00c000); //Green break;
case 4: mDrawable.getPaint().setColor(0xff0000ff); //Blue break;
case 5: mDrawable.getPaint().setColor(0xff0000ff); //Blue break;
case 6: mDrawable.getPaint().setColor(0xff696969); //Gray break;
case 7: mDrawable.getPaint().setColor(0xff696969); //Gray break;
case 8: mDrawable.getPaint().setColor(0xffffff00); //Yellow break;
case 9: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 10: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 11: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 12: mDrawable.getPaint().setColor(0xffa020f0); //Purple break;
case 13: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 14: mDrawable.getPaint().setColor(0xffffd700); //Gold break;
case 15: mDrawable.getPaint().setColor(0xffff6600); //Orange break;
} icon.setImageDrawable(mDrawable); icon.setPadding(5, 5, 5, 5);
This results in a space for the ImageView but no image.
View 1 Replies
Nov 2, 2010
I'm going to be using
setBackgroundResource(R.drawable.background)
in my onCreate() method.
When I create the XML file with the and its colors, what type of resource am I creating? "values", "layout"?
View 1 Replies
View Related
Aug 11, 2009
I'm trying to set the background of a webview to a drawable image resource in Android.From the sdk it seems something like this would work but it doesn't.
View 5 Replies
View Related
Nov 2, 2010
i am implementing puzzle game application in this application create one button in click the button display original image of the puzzle .original image display in dialog box then click ok return in to actual page how can implemented.
View 2 Replies
View Related
Nov 11, 2010
I want to show image from drawable folder using path (res/drawable/icon.png). I do not want to use R.drawable.icon. Please anybody know how to view the image using res/drawable/icon.png.
View 6 Replies
View Related
Oct 19, 2010
Is there a way to use an image size when setting the sizes of a view? I want to create a TextView item with the exact height of a resource image, but I don't want to use the image as a background for the text view.
View 1 Replies
View Related
Oct 10, 2009
I need to use some inbuild drawable I found in
http://developer.android.com/reference/android/R.drawable.html
I set drawable @drawable/ic_input_add to a button in my layout xml file. The add icon appears on the button of layout editor. But there is a error of that xml file said that
Description Resource Path Location Type ERROR Error: No resource found that matches the given name (at 'drawableLeft' with value '@drawable/ic_input_add'). spend_list.xml / AccountBook/res/layout line 5 Android AAPT Problem. How to use a inbuild drawable?
View 3 Replies
View Related
Aug 21, 2009
I have some image names stored in a database, but the images themselves are in the /res/drawable folder of the application. I need to assign these images to some views at runtime, and I'm currently doing it this way:
// public static final String DRAWABLES_PATH = ":drawable/";
int resId = getResources().getIdentifier(packageName+DRAWABLES_PATH +imageName,null,null); mButtonX.setBackgroundResource(resId); //
Is there a more efficient way to do it? Or should I be storing the images directly in the database (they are many)?
View 2 Replies
View Related
Dec 17, 2009
I need to create a tiled drawable using BitmapDrawable but I need to create it from xml resource rather than code.
View 3 Replies
View Related
May 13, 2010
I would like to get a byte array from an jpeg image located in my res/drawable file?
View 3 Replies
View Related
Feb 28, 2010
I have:
String uri = "@drawable/myresource.png";
How can I load that in ImageView? this.setImageDrawable?
View 2 Replies
View Related
Oct 19, 2010
Does all resource (all in res folder if on eclipse IDE), specially drawable image, is loaded to memory during runtime? Or it is just like a file which is available when the application need it?
View 1 Replies
View Related
Aug 18, 2009
I tried doing a ProgressBar and I wanted to change the background and the progress bar using my own drawables from the drawable resource. Is this possible? I just don't want to spend time creating my own custom component if can be done relatively easy.
View 4 Replies
View Related
May 28, 2010
Can I have sub-folders to hold my drawable resources. For example can I store an image in, say, 'res/drawable/content/images/myimage.jpg' and then find that resource via a call to:
id = context.getResources().getIdentifier("com.mycompany.myprog:drawable/ content/images/myimage", null, null);
I have tried this and it doesn't seem to be working (but I may have something wrong). Is it supposed to work or do all the resources need to be in the root drawable folder? Also, are jpeg files supported and drawable resources?
View 5 Replies
View Related
Oct 5, 2009
Is it possible to have subfolders in the /res/drawable directory. I would like my resources to be organized in a tree view and not in a flat dir. If it is possible so how do I reference the resource from the code?
View 3 Replies
View Related
Sep 1, 2010
I have an app with locally stored .jpg files. I would like to be able to send the images (1 at a time, on user interaction) to the Gallery app's activity using an explicit intent.
View 3 Replies
View Related
Jul 21, 2010
I use http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012 to load images in a ListView and a GridView. It works but the images are loaded form bpttom to top. How to fix that?
Bonus Question: Can I use a loading animation in a image view while the real image is loaded? Right now it's just a default image.
View 1 Replies
View Related
Mar 25, 2010
I am getting an error from Eclipse when I use this xml file (res / drawable/btnswitch.xml) to designate different button conditions
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_st_rd" />
<!-- pressed --> <item android:state_focused="true"
android:drawable="@drawable/btn_st_gr" /> <!-- focused --> <item android:drawable="@drawable/btn_st_gr" /> <!-- default --> </selector>
I call it in my layout file with this code:
<Button android:id="@+id/startTimer_btn" android:src="@drawable/btnswitch"" android:layout_width="wrap_content" android:layout_height="fill_parent" />
Eclipse says it can't run the configuration because I have errors but does not show any errors. And when I remove the xml code (to go back to my original code which just sets a background image for the Button) it says that now has errors. I have to restart Eclipse to get the original code to run again.
View 5 Replies
View Related
Sep 13, 2010
I've got a line in my manifest that looks like this:
<application android:icon="@drawable/icon" android:label="@string/ app_name" android:debuggable="true">
But I see the default Android icon on the desktop instead of the one in drawable/icon. What else do I need to do?
View 7 Replies
View Related
Jul 15, 2009
In my application I want to set the ringtone to one of the resources in my project. I have not got this to work, yet.
I'm setting the default ringer to a resource in my application with the following code.
CODE:...............
I can play the resource via the RingtoneManager with this code:
CODE:........
This plays the sound I would expect.
However, if I ask the RingtoneManager to play the default ringer, it plays the default android ringer. Here is the code I'm using to play the default ringer:
CODE:........
The question is... Why is the "setActualDefaultRingtoneUri" method call not setting the default ringer?
View 2 Replies
View Related
May 14, 2010
Does anyone know the syntax for an XML file for a single bitmap drawable resource? What I'm looking to do is "alias" a drawable in my app. I have need for the same image with 2 different names, and rather than including the image twice in my res/drawable directory, I'd rather alias it (it's fairly large). In other words, instead of:
res/drawable/name1.png res/drawable/name2.png
I'd like to have:
res/drawable/name1.png res/drawable/name2.xml
where name2.xml looks SOMETHING like this:
<?xml version="1.0" encoding="UTF-8" ?> <bitmap src="@drawable/name1" />
Is this possible? If so, any idea what the syntax should be? I can't find it in the docs, and I've had no luck with trial-and-error.
You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
View 6 Replies
View Related
Mar 16, 2010
I need to create a object Image from import javax.microedition.lcdui.Image; using a file .png placed in drawable folder. How can i do that?
View 1 Replies
View Related
May 1, 2010
I have the following drawable which draw a rectangle. Can you please tell me how can I add a 9patch image as the background of this drawable? code...
View 1 Replies
View Related
Jun 15, 2010
How can i get the resource id of an image if i know its name (in android)
View 1 Replies
View Related
Sep 9, 2009
On a layout I want to scale the background image (keeping its aspect ratio) to the space allocated when the page gets created. I am using layout.setBackgroundDrawable() and am using a BitmapDrawable to setGravity for clipping and filling, but don't see any option for scaling.
View 2 Replies
View Related
Sep 9, 2009
On a layout I want to scale the background image (keeping it's aspect ratio) to the space allocated when the page gets created. Anyone have any idea how to do this?
I am using layout.setBackgroundDrawable() and am using a BitmapDrawable to setGravity for clipping and filling, but don't see any option for scaling.
View 4 Replies
View Related
Nov 1, 2010
A number of images are "built in" to my app. They are stored in the drawable folder. I'd like to give the option of sending one of these images via mms (or even email) to someone in the user's address book. All the examples I've seen are sending images that are stored somewhere other then the default Eclipse drawable folders.
View 1 Replies
View Related
Sep 7, 2010
I want to download image from distant server and use it as resource. Is it possible ? How can I do this ?
View 2 Replies
View Related
Mar 17, 2010
I have a picture in res/drawable directory: res/drawable/picture.jpeg.
Can I dynamically update this picture.jpeg from code? i.e. I want to use another picture to replace this picture in the drawable directory dynamically. If I can, what path should I use to access the picture? Should I use "res/drawable/picture.jpeg"?
View 1 Replies
View Related
Nov 15, 2009
I have an app that I started in 1.6. It used images that were specific to portrait and landscape layouts. I put these in the corresponding drawable folders, for example:
drawable/image01,png
drawable-land/image01.png
when I created a new project with 2.0 it gave me the following folders. drawable drawable-hdpi drawable-mdpi drawable-lpdi. when I look at the documentation around these folders it all seems very straight forward. I assumed that you were able to create the following folders. drawable-hdpi-land drawable-mdpi-land drawable-lpdi-land
and everything would work as before. The image directory would swap automagically pulling the appropriately laid out image depending on your screen orientation. Unfortunately it does not. The SDK seems to get confused, and if I clean the project, the folders come up as poorly named.
View 3 Replies
View Related