Alex Rivera | Logout

flashing background

Asked 2013-03-11T04:46:59.773
8

I have a LinearLayout with a few Buttons and TextViews. I want my background to flash at timed intervals, say from red to white to red and so on. Right now, I am trying this code, but it gives me a null pointer exception.

LinearLayout ll = (LinearLayout) findViewById(R.layout.activity_main);
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); 
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
ll.startAnimation(anim); // shows null pointer exception at this line

Please help me where am I going wrong?

Edit
Report

1 Answer

6

Try this

LinearLayout ll = (LinearLayout) findViewById(R.id.activity_main);
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); 
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
ll.startAnimation(anim);

and If activity_main is your XML file name then

setContentView(R.layout.activity_main);

and use your layout id here

LinearLayout ll = (LinearLayout) findViewById(R.id.linear_layout_id);
answered 2013-03-11T04:57:13.533

Your Answer