The frame layout achieves the neon effect and the layout achieves the neon Effect
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.
1. First, the FrameLayout layout is used in XML, six TestView files are added, and the color and position are set.
The XML layout is as follows:
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" android:layout_gravity="right" android:width="160pt" android:height="160pt" android:background="#f00" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_gravity="right" android:width="140pt" android:height="140pt" android:background="#88ff00"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView3" android:layout_gravity="right" android:width="120pt" android:height="120pt" android:background="#ffffff"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView4" android:layout_gravity="right" android:width="100pt" android:height="100pt" android:background="#3be407"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView5" android:layout_gravity="right" android:width="80pt" android:height="80pt" android:background="#ffff88"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView6" android:layout_gravity="right" android:width="60pt" android:height="60pt" android:background="#8329c7"/></FrameLayout>
2. Easy to manage and call the six colors defined in colors. xml
<?xml version="1.0" encoding="utf-8"?><resources> <color name="color1">#f00</color> <color name="color2">#88ff00</color> <color name="color3">#ffffff</color> <color name="color4">#3be407</color> <color name="color5">#ffff88</color> <color name="color6">#8329c7</color></resources>
3. Main program code in MainActivity
Package happy. framelayout; import android. OS. bundle; import android. OS. message; import android. support. v7.app. appCompatActivity; import android. widget. textView; import java. util. timer; import java. util. timerTask; public class MainActivity extends AppCompatActivity {private int currentColor = 0; // define a color array final int [] colors = new int [] {R. color. color1, R. color. color2, R. color. color3, R. color. color4, R. color. color5, R. color. color6 ,}; final int [] names = new int [] {R. id. textView, R. id. textView2, R. id. textView3, R. id. textView4, R. id. textView5, R. id. textView6 ,}; TextView [] views = new TextView [names. length]; // handler receives the data sent by the main thread, and uses this data with the main thread to update the UI android. OS. handler handler = new android. OS. handler () {@ Override public void handleMessage (Message msg) {// indicates that the Message comes from the if (msg. what = 0x234) {// change the background of testView in sequence for (int I = 0; I <names. length; I ++) {// when a msg is received, the color of views starts to change once (six colors are changed according to the color of colors + currentcolor) views [I]. setBackgroundResource (colors [(I + currentColor) % names. length]);} currentColor ++;} // throw the message to the parent class to avoid the loss of super. handleMessage (msg) ;}}; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. test); for (int I = 0; I <names. length; I ++) {// set the initial color for views, (six testviews) views [I] = (TextView) findViewById (names [I]);} // define a thread to periodically change the currentColor variable value new Timer (). schedule (new TimerTask () {@ Override public void run () {// send an empty message to notify the system to change the background color of the six TextView components handler. sendEmptyMessage (0x234) ;}, 0,200 );}}
4. Dynamic neon Effect