Android study Note 6: Use Framelayout to achieve neon Effect

Source: Internet
Author: User

Framelayout is the frame layout, which can be used to overlay several controls. You can use Framelayout and textview to achieve a simple neon effect.


Package org. crazyit. framelayout;
 
Import java. util. Timer;
Import java. util. TimerTask;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. OS. Handler;
Import android. OS. Message;
Import android. widget. TextView;
 
Public class FrameLayoutTest extends Activity
{
Private int currentColor = 0;
// Define a color array
Final int [] colors = new int []
{
R. color. color7,
R. color. color6,
R. color. color5,
R. color. color4,
R. color. color3,
R. color. color2,
R. color. color1,
};
// Color display array, with the view as the TextView Control
Final int [] names = new int []
{
R. id. View01,
R. id. View02,
R. id. View03,
R. id. View04,
R. id. View05,
R. id. View06,
R. id. View07
};
TextView [] views = new TextView [7];
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
For (int I = 0; I <7; I ++)
{
Views [I] = (TextView) findViewById (names [I]);
}
// Use Handler for Message Processing
Final Handler handler = new Handler ()
{
@ Override
Public void handleMessage (Message msg)
{
// Indicates that the message is sent by the program.
If (msg. what = 0x1122)
{
// Change the background color of the seven textviews in sequence
For (int I = 0; I <7-currentColor; I ++)
{
Views [I]. setBackgroundResource (colors [I + currentColor]); // you can change the background color.
}
For (int I = 7-currentColor, j = 0; I <7; I ++, j ++)
{
Views [I]. setBackgroundResource (colors [j]);
}
}
Super. handleMessage (msg );
}
};
// Define a thread to change the currentColor variable value periodically
New Timer (). schedule (new TimerTask ()
{
@ Override
Public void run ()
{
CurrentColor ++;
If (currentColor> = 6)
{
CurrentColor = 0;
}
// Send a message to notify the system to change the background color of the seven TextView Components
Message m = new Message ();
// Define an identifier for the message
M. what = 0x1122;
Handler. sendMessage (m );
}
}, 0,100); // the cycle is 100 milliseconds
}
}
Package org. crazyit. framelayout;

Import java. util. Timer;
Import java. util. TimerTask;

Import android. app. Activity;
Import android. OS. Bundle;
Import android. OS. Handler;
Import android. OS. Message;
Import android. widget. TextView;

Public class FrameLayoutTest extends Activity
{
Private int currentColor = 0;
// Define a color array
Final int [] colors = new int []
{
R. color. color7,
R. color. color6,
R. color. color5,
R. color. color4,
R. color. color3,
R. color. color2,
R. color. color1,
};
// Color display array, with the view as the TextView Control
Final int [] names = new int []
{
R. id. View01,
R. id. View02,
R. id. View03,
R. id. View04,
R. id. View05,
R. id. View06,
R. id. View07
};
TextView [] views = new TextView [7];
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
For (int I = 0; I <7; I ++)
{
Views [I] = (TextView) findViewById (names [I]);
}
// Use Handler for Message Processing
Final Handler handler = new Handler ()
{
@ Override
Public void handleMessage (Message msg)
{
// Indicates that the message is sent by the program.
If (msg. what = 0x1122)
{
// Change the background color of the seven textviews in sequence
For (int I = 0; I <7-currentColor; I ++)
{
Views [I]. setBackgroundResource (colors [I + currentColor]); // you can change the background color.
}
For (int I = 7-currentColor, j = 0; I <7; I ++, j ++)
{
Views [I]. setBackgroundResource (colors [j]);
}
}
Super. handleMessage (msg );
}
};
// Define a thread to change the currentColor variable value periodically
New Timer (). schedule (new TimerTask ()
{
@ Override
Public void run ()
{
CurrentColor ++;
If (currentColor> = 6)
{
CurrentColor = 0;
}
// Send a message to notify the system to change the background color of the seven TextView Components
Message m = new Message ();
// Define an identifier for the message
M. what = 0x1122;
Handler. sendMessage (m );
}
}, 0,100); // the cycle is 100 milliseconds
}
}
Corresponding XML file


<? Xml version = "1.0" encoding = "UTF-8"?>
<FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<! -- Define 7 textviews in sequence, and the first defined TextView is located at the underlying layer
The defined TextView is located at the upper layer -->
<TextView android: id = "@ + id/View01"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "210px"
Android: height = "50px"
Android: background = "# ff0000"
/>
<TextView android: id = "@ + id/View02"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "180px"
Android: height = "50px"
Android: background = "# dd0000"
/>
<TextView android: id = "@ + id/View03"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "150px"
Android: height = "50px"
Android: background = "# bb0000"
/>
<TextView android: id = "@ + id/View04"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "120px"
Android: height = "50px"
Android: background = "#990000"
/>
<TextView android: id = "@ + id/View05"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "90px"
Android: height = "50px"
Android: background = "#770000"
/>
<TextView android: id = "@ + id/View06"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "60px"
Android: height = "50px"
Android: background = "#550000"
/>
<TextView android: id = "@ + id/View07"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: width = "30px"
Android: height = "50px"
Android: background = "#330000"
/>
</FrameLayout>

From the column hn307165411

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.