Android Footstep---Use framelayout to achieve neon effects

Source: Internet
Author: User

Rotate the background color of the 7 TextView in the frame layout, and the color gradient above will change continuously.

First layout in the Main.xml file

The overall layout for the framelayout in the middle of the 7 TextView, representing 7 different colors, you can see the same height, the width is gradually reduced, the newly added textview will not be completely obscured, set the color gradient

<framelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= "vertical" Androi      D:layout_width= "Fill_parent" android:layout_height= "Fill_parent" > <!--define 7 TextView in turn, the first defined TextView is on the bottom Post-defined TextView located on top---<textview android:id= "@+id/view01" android:layout_width= "Wrap_content" android:l ayout_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_cont Ent "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:w Idth= "150px" android:height= "50px" android:background= "#bb0000"/> <textview android:id= "@+id/vi Ew04 "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_conte NT "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:lay          out_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_con Tent "android:width=" 30px "android:height=" 50px "android:background=" #330000 "/> </f  Ramelayout>

  defined in mainactivity

Package com.example.framlayout;  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 Mainactivity 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, view for 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.activity_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 was sent from this program if (Msg.what = = 0 x1122) {//change the background color of 7 textview for (int i = 0; i < 7-curre Ntcolor;                       i++) {Views[i].setbackgroundresource (colors[i + currentcolor]);//Change background color                      } for (int i = 7-currentcolor, j = 0; i < 7; i++, J + +)                      {Views[i].setbackgroundresource (colors[j]);              }} super.handlemessage (msg);          }          }; Defines a thread that periodically changes the value of the CurrentColor variable to the new Timer (). scheduLe (new TimerTask () {@Override public void run () {Curren                  tcolor++;                  if (CurrentColor >= 6) {currentcolor = 0;                  }//Send a message to notify the system to change the background color of 7 textview components Message m = new Message ();                  Define an identity for the message m.what = 0x1122;               Handler.sendmessage (m); }}, 0, 100);  Period is 100 milliseconds}}

Use handler to handle updates to the TextView background color, define a thread to perform a task 0.1 seconds at a time, change the value of the CurrentColor variable only, and then send a message to handler notifying it to update the background color of 7 TextView.

Problem: Colors array the place in the EC was prompted by the color cannot be resolved or was not a field???

Colors array the place in the EC is prompted by the color cannot be resolved or isn't a field???
Because: you lack of color resource files, add the following <color.../> sub-elements in String.xml!!!

String.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <string name= "App_name" >framlayout</ string>    <string name= "action_settings" >Settings</string>    <string name= "Hello_world" >hello world!</string>    <color name= "Color1" > #0f0 </color>      <color name= "Color2" > #00f </color>      <color name= "Color3" > #0ff </color>       <color name= "Color4" > #f0f </ color>      <color name= "Color5" > #ff0 </color>       <color name= "Color6" > #07f </color>       <color name= "Color7" > #70f </color></resources>

Android Footstep---Use framelayout to achieve neon effects

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.