drawable

android - adding a String over a Drawable image?

这一生的挚爱 提交于 2019-11-30 05:43:37
I'm trying to add a String to a Drawable image. I'm currently not using a Panel to draw and I'd like to keep it that way. Any ideas or do I need to invoke an onDraw() method? My image is showing up with this code: Drawable image = getResources().getDrawable(tile_types[tileType]); setImageDrawable(image); I'd like to add a String over this image. Thanks. Sam's answer was my starting point, but the image didn't show up, only the text (I use it on a Google Map). Finally I got it working with a LayerDrawable . Here is my solution: private Drawable createMarkerIcon(Drawable backgroundImage, String

How to create a partially-rounded-corners-rectangular drawable with center-crop and without creating new bitmap?

二次信任 提交于 2019-11-30 05:31:16
问题 Background I've already seen how to create a drawable that's circular out of a bitmap, and also how to add an outline (AKA stroke) around it, here. The problem I can't find out how to do a similar task for rounding only some of the corners of the bitmap, inside the drawable, without creating a new bitmap, and still do it for a center-crop ImageView. What I've found This is what I've found, but it does create a new bitmap, and when using it in an imageView with center-crop (source here): /** *

Android Selector Drawable doesnt work with attributes

天大地大妈咪最大 提交于 2019-11-30 05:19:48
I am using attr to create a selector drawable for my project so that once i change theme colors, i dont have to make any change in the drawable file. I am using following libs: compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:cardview-v7:+' compile 'com.android.support:design:22.2.0' Here is the source code for drawable: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="?attr/colorPrimary" android:state_enabled="true" android:state_window_focused="false"/> <item android:drawable="?attr

draw only a portion of a Drawable/Bitmap

梦想的初衷 提交于 2019-11-30 04:48:23
问题 I was wondering if it is possible to draw only a portion of a bitmap after it is loaded into memory without creating a new Bitmap. I see Drawable has a setBounds method but im not sure if it only draws the area set or just resizes the entire image. Thank you. 回答1: Assuming you have a main canvas to draw to, you can use one of the drawBitmap methods of the Canvas class to draw a subset of the loaded bitmap. public void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint) 回答2: I searched

Is it possible to have an animated drawable?

孤者浪人 提交于 2019-11-30 04:12:49
Is it possible to create a drawable that has some sort of animation, whether it is a frame by frame animation, rotation, etc, that is defined as a xml drawable and can be represented by a single Drawable object without having to deal with the animation in code? How I am thinking to use it: I have a list and each item in this list may at sometime have something happening to it. While it is happening, I would like to have a spinning progress animation similar to a indeterminate ProgressBar. Since there may also be several of these on screen I thought that if they all shared the same Drawable

Consequences of drawable.setCallback(null);

回眸只為那壹抹淺笑 提交于 2019-11-30 03:57:47
While trying to implement small in-memory cache of Drawables, I learned that to avoid memory leaks after closing activity I need to unbind those Drawables: set their callback to null. Because maintaining Drawables cached in each activity would require extra code, I tried to unbind them immediately after setImageDrawable(drawable) and I don't see any consequences so far. This is code from MyImageView class ( extends ImageView ): setImageDrawable(drawable); d.setCallback(null); In debugger I can clearly see that before first line callback is null, after first line it is set to this imageView,

android: fit height of DrawableLeft in a textView

送分小仙女□ 提交于 2019-11-30 02:59:12
I am trying to display a blue line next to a block of text, pretty much like this: Here's my code: <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/blue_line" /> blue_line is a jpg file. a blue rectangle. it displays in its original size regardless of the text in the textview. how can i adjust its height dynamically according to the height of the text? like make it shorter when theres little amount of text and longer when there's more text.... vipul mittal You can try doing it in code by setting

Shape Drawables on Samsung devices default to black background

丶灬走出姿态 提交于 2019-11-30 00:18:39
问题 So I'm developing using a Samsung Note 2 device and for some reason when I create this drawable <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dp" /> <stroke android:width="1dp" android:color="@color/grey_light" /> </shape> and apply it as a background to a LinearLayout, it makes the background black, If I remove the background attribute of the LinearLayout altogether it stays transparent, only when I apply a drawable to it does it turn black.

Android TextView drawable, change padding between drawable and text?

﹥>﹥吖頭↗ 提交于 2019-11-30 00:05:38
问题 I am creating a TextView with a drawable underneath, in a GridLayout . I want to bring the drawable to the middle of the TextView ; I tried with setCompoundDrawablePadding(-75) and it only changes the position of the text. Current code: TextView secondItem = new TextView(this); GridLayout.LayoutParams second = new GridLayout.LayoutParams(row2, col1); second.width = halfOfScreenWidth; second.height = (int) (quarterScreenWidth * 1.5); secondItem.setLayoutParams(second); secondItem

Is there a way to set drawable's Alpha using XML?

三世轮回 提交于 2019-11-29 22:49:05
Easy like itself . I wanna make an alpha button , which would have a selected drawable this way: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Play/Pause --> <item android:state_selected="false" android:drawable="@drawable/item" /> <item android:state_selected="true" android:drawable="@drawable/item" /> </selector> I would wanna make something like this: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Play/Pause --> <item android:alpha="125" android:state