drawable

Performance wise, what is typically better, using an image or a xml created shape as a drawable?

天大地大妈咪最大 提交于 2019-11-27 17:50:52
问题 For example, if each row in a list had a background that was a gradient, would it be better to use a image of a gradient or to define that gradient in a shape drawable in xml? Is there is significant performance difference between the two methods? 回答1: I just asked a similar question and it sounded like that using an image drawable is more efficient computationally than using a vector.(but i'm not expert so don't quote me on that) It really depends on what your trying to set out to achieve in

Combine image and text to drawable

荒凉一梦 提交于 2019-11-27 17:44:37
I want to create a drawable, which consists of a map pin(bubble) and some text. The bubble should be in the background and the text in the foreground. This drawable should be passed in super(drawable) of the class BalloonItemizedOverlay which extends ItemizedOverlay<Item> . In other words, I want to show text in the bubble that appears in the map. I am using the Hello Mapview tutorial Marmoy This method takes a drawable from your resources, draws some text on top of it and returns the new drawable. All you need to do is give it the resource id of your bubble, and the text you want on top. Then

How to create Drawable from resource

匆匆过客 提交于 2019-11-27 17:08:32
I have a image res/drawable/test.png (R.drawable.test). I want to pass this image to a function which accepts Drawable . (e.g. mButton.setCompoundDrawables()) So how to convert a image resource to an Drawable ? Your Activity should have the method getResources. Do: Drawable myIcon = getResources().getDrawable( R.drawable.icon ); daniel kilinskas This code is deprecated: Drawable drawable = getResources().getDrawable( R.drawable.icon ); Use this instead: Drawable drawable = ContextCompat.getDrawable(getApplicationContext(),R.drawable.icon); The getDrawable (int id) method is depreciated as of

Android, Drawable.createFromStream(is, srcname): what's the 2nd parameter meaning?

时间秒杀一切 提交于 2019-11-27 15:27:19
问题 Which is the meaning of the second parameter of Drawable.createFromStream() method? From Android APIs I only get: public static Drawable createFromStream (InputStream is, String srcName) Create a drawable from an inputstream In all examples I have read I see they use the string "src": is it the name of the directory where the drawable is cached, relative to my application's root dir? One parallel question: where am I supposed to find Android core sources (for example of Drawable

Prevent Proguard to remove specific drawables

倖福魔咒の 提交于 2019-11-27 15:03:38
In my Android project, I have some images stored in res/drawable/ which are accessed only from an HTML file loaded in a Webview. For example (code in HTML): <img src="file:///android_res/drawable/myfriend.png"> These images are removed by Proguard from apk during optimization. Does somebody know a way to keep these files (even if they are not used directly in the java code)? I had a similar issue and wanted to add just a few bits. The resources ARE NOT stripped away by ProGuard. If you simply unzip your apk you will see that the image files are still there. The problem is that the Webkit

Drawable shape not showing when used in combination with android:drawableBottom attribute.

半城伤御伤魂 提交于 2019-11-27 14:52:18
问题 XML file saved at res/drawable/gradient_box.xml: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /> </shape> (The above shape definition is is taken from then Android developer guide. There's no errors

Sub folders in drawable resource folder? [duplicate]

こ雲淡風輕ζ 提交于 2019-11-27 14:26:31
This question already has an answer here: Can the Android drawable directory contain subdirectories? 20 answers How to access res/drawable/“folder” 5 answers I would like to create sub folders in drawable folder. I have a lot of file(such as png, xml) in drawable folder. I want to create sub folders in there to find the files easily. Can I create sub folders like that? Thanks. This is now (sort of) possible by using Android Studio and Gradle. Whilst subfolders are still not possible, it is possible to separate resources into different sets and have them merged by the build system . As an

Refreshing a LinearLayout after adding a view

让人想犯罪 __ 提交于 2019-11-27 13:41:54
I'm trying to add views dynamically to a linearlayout. I see through getChildCount() that the views are added to the layout, but even calling invalidate() on the layout doesn't give me the childs showed up. Am I missing something? A couple of things you can check in your code: On the View that is being added, check that you call its setLayoutParameter method with an appropriate ViewGroup.LayoutParameter . When you adding the new View s, make sure you are doing it on the UI thread. To do this, you can use the parent View 's post method. This self contained example adds a TextView after a short

How can I set the color of android rating bar's stroke? (Not the color of the stars but the BORDER)

浪子不回头ぞ 提交于 2019-11-27 13:32:45
问题 I am an android beginner and I want to make my custom ratingBar. Disclaimer: it's not a duplicate. because all the posts I have read asks about how to change colors of the star and how to remove the stroke. That is NOT what I want. I want to have the stroke and to be able to change the color of the border. With a transparent and yellow stroke while empty, and yellow background and stroke for half and filled. I do NOT want to use pngs. I have my own already but they are too small. I just dont

Align top of image to top of TextView

≡放荡痞女 提交于 2019-11-27 13:26:40
I want to create a layout that aligns the top of an image to the top of a TextView like this: --------- Text text text text text text text | Image | text text text text text text text --------- text text text text text text text text text text text text text text text text text text text. I tried doing this by setting android:drawableLeft to my image, but that centers the image vertically: Text text text text text text text --------- text text text text text text text | Image | text text text text text text text --------- text text text text text text text text text text text text. Is this