I am trying to build a wellcome screen where the application banner fades in slowly at the time the initial layout is loaded.
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.
The XML with a static image used to look like this:
<ImageView
android:src="@drawable/logosmall"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageLogo"/>
I just load logosmall here and it works nice, but the logo is fully visible from start.
and the new xml to call my custom ImageView class is almost identical:
<com.mydomainhere.customImageView
android:src="@drawable/logosmall"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageLogo"/>
The custom class code is pretty simple, I just need to override the onDraw method and invalidate.
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 > 254){
mDelta = -1f;
}
if (mAlpha < 1){
mDelta = 1f;
}
mAlpha = mAlpha + mDelta;
this.setAlpha((int)mAlpha);
this.invalidate();
}
}
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.
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.
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.
Thanks in advance for your help.