android-drawable

Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi

蹲街弑〆低调 提交于 2019-11-26 22:58:07
问题 I have a rough idea of what each of these directories are for, but I'm not really clear on the concept and I have some specific questions. For example, what are the target DPIs for each directory? When you create an asset, should it be at that target DPI or should it be at the more normal 72dpi screen DPI? If you're targeting multiple devices, is it ever appropriate to put a PNG in drawable or should you always have multiple versions slightly tailored to the specific screens? Thanks. 回答1: As

How to draw a circle inside a circle using Android xml shapes?

霸气de小男生 提交于 2019-11-26 22:16:12
问题 I'm trying to make a thumb for a seekbar for my app, and I want to have an inner circle surrounded by a different, larger (semi-transparent) outer circle. I'm trying to use layer-list , but I'm having issues. Below is my code... <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="oval" > <solid android:color="#00f" /> <size android:height="15dp" android:width="15dp" /> </shape> </item> <item> <shape

Drawable image on a canvas

被刻印的时光 ゝ 提交于 2019-11-26 21:53:19
How can I get an image to the canvas in order to draw on that image? The good way to draw a Drawable on a canvas is not decoding it yourself but leaving it to the system to do so: Drawable d = getResources().getDrawable(R.drawable.foobar, null); d.setBounds(left, top, right, bottom); d.draw(canvas); This will work with all kinds of drawables, not only bitmaps. And it also means that you can re-use that same drawable again if only the size changes. You need to load your image as bitmap: Resources res = getResources(); Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.your_image);

How can I recreate this background in xml?

ε祈祈猫儿з 提交于 2019-11-26 21:22:05
问题 I've been trying to recreate a background image in xml (as drawable). Since the background is a simple shape, it would be better if it is created as xml drawable. The is a really large gradient circle that squares off at the left, top and right border. What I've tried <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <size android:height="20dp" /> <gradient android:type="linear" android

android:drawableLeft margin and/or padding

可紊 提交于 2019-11-26 21:17:53
Is it possible to set the margin or padding for the image which we added with the android:drawableLeft ? As cephus mentioned android:drawablePadding will only force padding between the text and the drawable if the button is small enough. When laying out larger buttons you can use android:drawablePadding in conjunction with android:paddingLeft and android:paddingRight to force the text and drawable inward towards the center of the button. By adjusting the left and right padding separately you can make very detailed adjustments to the layout. Here's an example button that uses padding to push

Programmatically set left drawable in a TextView

∥☆過路亽.° 提交于 2019-11-26 21:16:41
I have a textView in xml here. <TextView android:id="@+id/bookTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:drawableLeft="@drawable/checkmark" android:gravity="center_vertical" android:textStyle="bold" android:textSize="24dip" android:maxLines="1" android:ellipsize="end"/> As you can see I set the DrawableLeft in xml. I would like to change the drawable in code. Is there anyway to go about doing this? Or setting the drawableLeft in code for the text view? BrainCrash You can use setCompoundDrawablesWithIntrinsicBounds(int left,

Custom ProgressBar

淺唱寂寞╮ 提交于 2019-11-26 20:44:26
I am trying to create a ProgresBar that looks like the following: So far, I have created an object which extends ProgressBar, and now I am trying to figure out what my next step is. I know that I need to override onDraw() with some logic that will decide how many squares to color in. This is trivial. What I don't know how to do is get these squares in the first place. How can I replace the default drawable, so when I add my custom bar in the layout I can see something like my image? try this custom Drawable: class ProgressDrawable extends Drawable { private static final int NUM_RECTS = 10;

Drawable vs. Bitmap [duplicate]

六眼飞鱼酱① 提交于 2019-11-26 20:06:17
问题 This question already has answers here : What is the difference between Bitmap and Drawable in Android? (4 answers) Closed 3 years ago . I am writing a real-time game for Android, and after looking at some code from the samples provided in the SDK, I am confused as to when I should use Bitmap or Drawable for my sprites in my game. What's the difference? Which one is better (faster) for sprites and which one is better for a static background? 回答1: To get an idea which is better you may want to

Android shape border with gradient

五迷三道 提交于 2019-11-26 19:49:55
问题 I want to create a border for a linearLayout. So I decide to create a shape. I want the border to have a gradient. The following is not doing it. It fills the rectangle and then creates a stroke. I don't want a filled rectangle, just the stroke. And I want to apply the gradient to the stroke. <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="360" android:centerColor="#e95a22" android

Calling setCompoundDrawables() doesn't display the Compound Drawable

我是研究僧i 提交于 2019-11-26 18:49:13
问题 After I call the setCompoundDrawables method, the compound Drawable is not shown.. Drawable myDrawable = getResources().getDrawable(R.drawable.btn); btn.setCompoundDrawables(myDrawable, null, null, null); Any thoughts? 回答1: I needed to be using setCompoundDrawablesWithIntrinsicBounds. 回答2: Use This (I tested). It works good Drawable image = context.getResources().getDrawable( R.drawable.ic_action ); int h = image.getIntrinsicHeight(); int w = image.getIntrinsicWidth(); image.setBounds( 0, 0,