What do I need to put in for an attribute if I want to put a null there?
For example, this piece of code:
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/ef_gradient_blue" />
<item android:drawable="@null" />
</transition>
But this won't work, as my app crashes when it tries to load this drawable. I need it to be null, so it can make a transition from fully opaque to completely see through.
In my Java, I load it like this:
mTransitionBlue = (TransitionDrawable)mProjectResources.getDrawable(R.drawable.transition_blue);
But I get a runtime exception from this, saying it can't find the transition_blue.xml, which is the XML specified before. So how do I achieve this?
In an XML document, the usual way to represent a null value is to leave the element or attribute empty. Some business messages use a special value to represent a null value: <price>-999</price> . This style of null representation is supported by the DFDL and MRM parsers.
Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources).
A View occupies a rectangular area on the screen and is responsible for drawing and event handling. Views are used for Drawing Shapes like Circles,Rectangles,Ovals etc . Just Use View with background and apply a Shape using Custom Drawable.
You should use a transparent drawable there (android lib has it predefined):
<transition xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/ef_gradient_blue" />
<item android:drawable="@android:color/transparent" />
</transition>
the @android:color/transparent
's value is #00000000
. It's important to have the first two digits 0, since they define the alpha value of the color (the rest is red, green and blue).
So you can use
<item android:drawable="#00000000" />
as well, or redefine it among your colors.
For reference you could take a look at the Android Developers 2D Graphics
and Transition Drawables
articles.
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