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).
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.
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? 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.
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.
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With