"Go" Android layer boot Help interface production

Source: Internet
Author: User

2012-11-02 10:31 1979 people read comments (0) favorite reports

Original: http://www.cnblogs.com/beenupper/archive/2012/07/18/2597504.html

The project was finished, and did the first start, sliding the boot page.

Then the need to change into a popular layer image guide.

Everyone must also see it often, the realization of course is very simple. Add a layer on the framelayout and you're done. Let it disappear after clicking.

Well, so many interfaces, do you want to change the layout of all the interfaces? Change to the root element and then set a layer of framelayout?

Here to see my decorview analysis of the children's shoes, must be very to feel. Setcontentview the parent element of the loaded layout is not framelayout?

So we're going to go straight up to the top of it and just boot the layer? Very good!

Method:

1.

Just to figure out how to find that framelayout, the way I think about it is to set an ID for each of the root elements of the XML layout, and find out through Findviewbyid how we set the layout through Setcontentview,

Then through the view of the View.getparent (), get its parent element. Its parent element is not the framelayout of what we want?

Then create a ImageView setting on the boot picture to add to the framelayout on it.

With a lot of activity, of course, we're going to put this public thing in all your activity's parent class. I'm a basicactivity here. A method for adding a boot picture is called in OnStart.

2.

There is no need to boot again because of the guided interface. So you have to save the record. This is saved in preference settings, and if the activity is booted, the full name of the class is saved.

Because the preferences can only save the key value (Key-value) pair, save multiple class names, I use |a|b|c this form to save as value.


Code:

ID added on root element in Main.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:orientation=" vertical "    android:layout_width=" fill_parent "    android:layout_height=" Fill_parent "    android:id=" @id/my_content_view "    ><textview      android:layout_width=" Fill_parent "     android:layout_height= "wrap_content"     android:text= "@string/hello"    /><button    android: Layout_width= "Wrap_content"     android:layout_height= "wrap_content"     android:id= "@+id/btn"    android: text= "Open sub"    /></linearlayout>

The ID is defined in the Ids.xml under Res/values

<?xml version= "1.0" encoding= "Utf-8"? ><resources><item type= "id" name= "my_content_view" ></ Item></resources>

Basicactivity Code:

Package Com.my.decorview.test;import Android.app.activity;import Android.view.view;import android.view.ViewGroup; Import Android.view.viewparent;import android.widget.framelayout;import android.widget.imageview;/** * @author Dawning Polis *http://www.cnblogs.com/beenupper/ * */public class Basicactivity extends Activity {private int guideresourceid=0;//boot page picture resource ID @Override protected        void OnStart () {Super.onstart (); Addguideimage ();//Add Boot page}/** * Add boot picture */public void Addguideimage () {View view = GetWindow (). GE        Tdecorview (). Findviewbyid (R.id.my_content_view);//Find the root layout on Setcontentview if (view==null) return;        if (mypreferences.activityisguided (this, This.getclass (). GetName ())) {//boot over return;        } viewparent viewparent = View.getparent ();            if (viewparent instanceof framelayout) {final Framelayout framelayout = (framelayout) viewparent;                if (guideresourceid!=0) {//Set boot picture final ImageView guideimage = new ImageView (this); Framelayout.layoutparams params = new Framelayout.layoutparams (ViewGroup.LayoutParams.FILL_PARENT,                ViewGroup.LayoutParams.FILL_PARENT); Guideimage.setlayoutparams (params);
Guideimage.setscaletype (SCALETYPE.FIT_XY); Guideimage.setimageresource (Guideresourceid); Guideimage.setonclicklistener (New View.onclicklistener () {@Override public void OnC Lick (View v) {Framelayout.removeview (guideimage); Mypreferences.setisguided (Getapplicationcontext (), BasicActivity.this.getClass (). GetName ());//Set as booted} }); Framelayout.addview (guideimage);//Add Boot Picture}}}/** subclass called in OnCreate, set the resource ID of the boot picture * and set android:id= on the root element of the layout xml "@id/my_content_view" * @param resId */protected void Setguideresid (int resId) { This.guideresourceid=resid; }}

Preferences code:

Package Com.my.decorview.test;import android.content.context;/** * @author Dawning Polis *http://www.cnblogs.com/beenupper/  * */public class Mypreferences {//Preferred file name public static final String sharedpreferences_name = "My_pref";        Boot interface KEY private static final String key_guide_activity = "guide_activity"; /** * Determine if activity has been guided * * @param context * @return has been booted true boot false not booted */public static Boo Lean activityisguided (Context context,string className) {if (Context==null | | classname==null| | "".        Equalsignorecase (ClassName)) return false; string[] Classnames = context.getsharedpreferences (Sharedpreferences_name, context.mode_world_readable). g Etstring (Key_guide_activity, ""). Split ("\\|"); /Get all class names such as Com.my.MainActivity for (string string:classnames) {if (Classname.equalsignorecase (String))            {return true;    }} return false; }/** set the activity to be booted. Save the class name as |a|b|c as value, because you can only save key-value pairs * @param context * @param className */public static void setisguided (Context context,string className) {if (Context==null | | classname==null| | "".        Equalsignorecase (ClassName)) return; String classnames = context.getsharedpreferences (Sharedpreferences_name, context.mode_world_readable). Get        String (Key_guide_activity, ""); StringBuilder sb = new StringBuilder (classnames). Append ("|"). Append (className);//Add Value context.getsharedpreferences (Sharedpreferences_name, context.mode_world_readable)//    Save the modified value. Edit (). putstring (Key_guide_activity, sb.tostring ()). commit (); }}

Adding a guide page in mainactivity

Package Com.my.decorview.test;import Android.content.intent;import Android.os.bundle;import Android.view.View; Import Android.widget.button;public class Mainactivity extends Basicactivity {    /** called when the activity is first C Reated. *    /@Override public    void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.main);                Button btn = (button) Findviewbyid (R.ID.BTN);        Btn.setonclicklistener (New View.onclicklistener () {            @Override public            void OnClick (View v) {                StartActivity (New Intent (Mainactivity.this, Subactivity.class));            }                    );                                Setguideresid (R.DRAWABLE.YINDAO01);//Add a boot page    }}

OK is done. Just two things to do

1. Call Setguideresid (int resId) in OnCreate in Basicactivity's subclass, set the boot picture resource ID

2. Add android:id= "@id/my_content_view" on the root element of the layout xml

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.