Frame layout (framelayout) of the Marquee

Source: Internet
Author: User

Spectator, today, the main learning is that the layout of the frame layout framelayout.

Where does this thing come from: Framelayout directly to the ViewGroup component.

What is the control of its child elements: its child elements are controlled by Framelayout.layoutparams. Yes, it's under control. We can set the Android.layout_gravity property (relative to the parent container's alignment setting)

It features: It creates an empty area (one frame) for each component that is added, and the components are superimposed together , and the stacking order is the last component displayed at the top level.

The basic concept is such a situation! Direct completion of the marquee example

New project not much to say.

1. Prepare color Resources

Create a new Color.xml color resource file under the Res/values folder

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <Colorname= "L_fl_c_c1">#27AF7D</Color>    <Colorname= "L_FL_C_C2">#AF2777</Color>    <Colorname= "L_FL_C_C3">#B1981A</Color>    <Colorname= "L_fl_c_c4">#9B15D4</Color>    <Colorname= "L_fl_c_c5">#13A8AA</Color>    <Colorname= "L_fl_c_c6">#B89009</Color></Resources>
View Code


2. Create a new layout file Activity_frame_layout.xml

<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#000000">     <TextViewAndroid:id= "@+id/l_fl_txtv0"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Top|center"Android:textcolor= "#fff"Android:text= "Rotate color value test"/>        <TextViewAndroid:id= "@+id/l_fl_txtv1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:width= "320DP"Android:height= "320DP"android:layout_gravity= "Center"Android:background= "@color/l_fl_c_c1"/>        <TextViewAndroid:id= "@+id/l_fl_txtv2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:width= "280DP"Android:height= "280DP"android:layout_gravity= "Center"Android:background= "@color/l_fl_c_c2"/>    <TextViewAndroid:id= "@+id/l_fl_txtv3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:width= "240DP"Android:height= "240DP"android:layout_gravity= "Center"Android:background= "@color/l_fl_c_c3"/>    <TextViewAndroid:id= "@+id/l_fl_txtv4"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:width= "200DP"Android:height= "200DP"android:layout_gravity= "Center"Android:background= "@color/l_fl_c_c4"/>    <TextViewAndroid:id= "@+id/l_fl_txtv5"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:width= "160DP"Android:height= "160DP"android:layout_gravity= "Center"Android:background= "@color/l_fl_c_c5"/>    <TextViewAndroid:id= "@+id/l_fl_txtv6"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:width= "120DP"Android:height= "120DP"android:layout_gravity= "Center"Android:background= "@color/l_fl_c_c6"/>   </Framelayout>
View Code

3. Background Code Implementation

ImportJava.util.Timer;ImportJava.util.TimerTask;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.os.Message;Importandroid.app.Activity;ImportAndroid.view.Menu;ImportAndroid.widget.TextView; Public classFramelayoutactivityextendsActivity {Private intCurrentcolor=0; //Color Resources    Final int[] colors=New int[]{r.color.l_fl_c_c1, R.color.l_fl_c_c2, R.COLOR.L_FL_C_C3, R.COLOR.L_FL        _C_C4, R.COLOR.L_FL_C_C5, r.color.l_fl_c_c6}; //array of control IDs    Final int[] txtvids=New int[]{r.id.l_fl_txtv1, R.ID.L_FL_TXTV2, R.ID.L_FL_TXTV3, R.ID.L_FL_TXTV4,             R.ID.L_FL_TXTV5, R.ID.L_FL_TXTV6}; Textview[] Txtvs=NewTextview[txtvids.length]; Handler Handler=NewHandler () {@Override Public voidhandlemessage (Message msg) {//TODO auto-generated Method StubString mes= "Rotate color value test (component id--color value)//"; if(msg.what==200){                 for(inti=0;i<txtvids.length;i++) {Txtvs[i].setbackgroundresource (colors[(i+currentcolor)%Txtvids.length]); Mes+=txtvs[i].getid () + "--" +colors[(i+currentcolor)% txtvids.length]+ "//"; } TextView T1=(TextView) Findviewbyid (r.id.l_fl_txtv0);                T1.settext (MES); CurrentColor++; }            Super. Handlemessage (msg);        }    }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_frame_layout);  for(inti=0;i<txtvids.length;i++) {Txtvs[i]=(TextView) Findviewbyid (Txtvids[i]); }        //define a thread cycle change CurrentColor value        NewTimer (). Schedule (NewTimerTask () {@Override Public voidrun () {Handler.sendemptymessage (200); }        },0,250); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (r.menu.frame_layout, menu); return true; }}
View Code

Note: Why not rotate the color code directly in the run () method, because the View and UI components in Android are not thread-safe and stipulate that thread threads are not allowed to access the UI components of the user interface.

The above is the realization of the example of the marquee, we can adjust a few textview components of the android.layout_gravity or layout_margin affect the layout of the properties, see what will happen, and what will not change.

The result of my own debugging is that, regardless of the layout position, the component is displayed in the top-most way.

^_^ spectators, if this article is of some help to you, then sweep it! ^_^

Frame layout (framelayout) of the Marquee

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.