Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a drawable shape have it's size set to fill_parent?

Is it valid for a drawable shape in Android to use fill_parent for it's size?

<shape     xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="oval">  <solid         android:color="#666666"/>  <size         android:width="fill_parent"         android:height="fill_parent"/> </shape> 

EDIT

This for the background of ImageButton views. I want the icon for the button to have a circle behind it, but I don't always know what the size of the button will be (different sizes per layout).

like image 445
Reactgular Avatar asked Jun 14 '13 14:06

Reactgular


People also ask

How do you change drawable size on android?

Once you import svg file into Android Studio project, you are going to see <vector> resource then just change the size as you want by width , height attributes. viewportWidth and viewportHeight is to set size for drawing on virtual canvas.

What is v24 in android drawable?

Classic drawable resources such as images are stored in the drawable folder. In contrast, vector drawables are stored in drawable-v24 . For this project, keep the drawable default and click OK. You should now see the New File dialog box.

What are Drawables?

What are Drawables? A Drawable resource is a general concept for a graphic which can be drawn. The simplest case is a graphical file (bitmap), which would be represented in Android via a BitmapDrawable class. Every Drawable is stored as individual files in one of the res/drawable folders.

How do you make a rectangle drawable on android?

You can create a new XML file inside the drawable folder, and add the above code, then save it as rectangle. xml. To use it inside a layout you would set the android:background attribute to the new drawable shape.


2 Answers

Not really. Not using a ShapeDrawable alone. If you go through the ShapeDrawable document, you will see (you are already using them in the tag) that the only valid attributes there are px, dp, sp, in and mm

A quote from the doc: android:width="...."

Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters) This is true for the attribute: android:height

This is speculation on my part, but I suspect why the fill_parent attribute value will not work is because a ShapeDrawble, unlike an XML Layout file will not have a parent container.

Leaving out the <size.... /> attribute entirely and setting the layout_width and layout_height on a Widget that will reference the said ShapeDrawable is the only option I suspect (if the fill_parent is to be honored).

like image 92
Siddharth Lele Avatar answered Sep 20 '22 21:09

Siddharth Lele


I don't know which API level this took effect, but per the Shape drawable documentation, it will be scaled proportionately to fit the view. So you can, for example, put width=1dp and height=1dp. See https://stuff.mit.edu/afs/sipb/project/android/docs/guide/topics/resources/drawable-resource.html#Shape

like image 24
androidguy Avatar answered Sep 22 '22 21:09

androidguy