Android ImageView that fades in and out by controlling its transparency
<p>I am trying to build a wellcome screen where the application banner fades in slowly at the time the initial layout is loaded.</p>

<p>A simple approach I'd like to folow is just extending the imageView class to include my fade in fade out code in the onDraw method but for some reason Android will just not render the ImageView at all.</p>

<p>The XML with a static image used to look like this:</p>

<pre><code>    &lt;ImageView
android:src="@drawable/logosmall"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageLogo"/&gt;
</code></pre>

<p>I just load logosmall here and it works nice, but the logo is fully visible from start.</p>

<p>and the new xml to call my custom ImageView class is almost identical:</p>

<pre><code>&lt;com.mydomainhere.customImageView
android:src="@drawable/logosmall"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageLogo"/&gt;
</code></pre>

<p>The custom class code is pretty simple, I just need to override the onDraw method and invalidate.</p>

<pre><code>public class customImageView extends ImageView{
    private float mAlpha = 5f;
    private float mDelta = 1f;

    public customImageView(Context context) {
        super(context);
    }

    public customImageView(Context context, AttributeSet attrs) {
        super(context);
        this.setAlpha((int)mAlpha);

    }


    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (mAlpha &gt; 254){
            mDelta = -1f;
        }
        if (mAlpha &lt; 1){
            mDelta = 1f;
        }
        mAlpha = mAlpha + mDelta;
        this.setAlpha((int)mAlpha);

        this.invalidate();    
   }

}
</code></pre>

<p>So I was expecting this code to give me a nice logo or banner that fades in and out in the initial wellcome screen but Android is somehow failing to load my "smalllogo" at all from the xml.</p>

<p>At this stage I am more worried about having the ability to use custom componets in the XML and whether android will be capable of rendering the XML right or not, I must be doing something wrong coz this looks pretty simple to me.</p>

<p>If the logo png file is loaded from the java everything looks fine but it looks like android is uncapable of loading the logo pgn file from the xml despite my class being just and extension of the standard ImageView class.</p>

<p>Thanks in advance for your help.</p>
