This is an example of an Android open screen layout that can be used to load advertising pictures and countdown layouts. Program set the Layoutparams, dividing the extra space ratio of 6 5, the specific weight ratio can be defined according to the user's own needs, asynchronous loading ads pictures, related to the Android code.
The specific implementation code is as follows:
Package cn.waps.extend;
Import android.app.Activity;
Import Android.content.Context;
Import android.content.res.Configuration;
Import Android.graphics.Color;
Import android.graphics.drawable.ShapeDrawable;
Import Android.graphics.drawable.shapes.RoundRectShape;
Import Android.os.AsyncTask;
Import Android.os.Handler;
Import Android.os.Looper;
Import android.view.Gravity;
Import Android.view.View;
Import Android.view.ViewGroup.LayoutParams;
Import Android.widget.LinearLayout;
Import Android.widget.RelativeLayout;
Import Android.widget.TextView;
Import Com.qcn.wzlz.AppConnect;
Import Com.qcn.wzlz.SDKUtils;
public class Loadingpopad {private final static Handler Mhandler = new Handler ();
private static Loadingpopad Loadingapppopad;
public static Loadingpopad getinstance () {if (Loadingapppopad = null) {Loadingapppopad = new Loadingpopad ();
} if (looper.mylooper () = = null) {Looper.prepare ();
return loadingapppopad; /** * Get open screen layout * @param context * @param time * @return */Public View Getcontentview (context, int time) {return getloadinglayout (context, time); Private LinearLayout Getloadinglayout (final context, final int time) {//overall layout linearlayout layout = new Linea
Rlayout (context);
Layout.setorientation (linearlayout.vertical);
Layout.setgravity (Gravity.center);
int bg_id = Context.getresources (). Getidentifier ("Loading_bg", "drawable", Context.getpackagename ());
if (bg_id!= 0) {layout.setbackgroundresource (bg_id);
//Load advertising picture and countdown layout, with linearlayout l_layout = new LinearLayout (context);
L_layout.setgravity (Gravity.center); Set Layoutparams, divide the extra space ratio to 6 5 (the specific weight ratio can be customized according to their own needs) L_layout.setlayoutparams (new Linearlayout.layoutparams (
Layoutparams.fill_parent, Layoutparams.fill_parent, 1f));
Load the layout of the picture relativelayout pop_layout = new Relativelayout (context);
TextView Timeview = new TextView (context);
Timeview.settext ("remaining" + Time + "seconds");
Timeview.settextsize (10);
Timeview.settextcolor (Color.Black); Timeview.setpaddinG (8, 3, 6, 2);
int num = 12;
Screen judgment of the mobile phone int displaysize = sdkutils.getdisplaysize (context);
if (displaysize = =) {num = 8;
}else if (displaysize = =) {num = 6;
}else if (displaysize = = 720) {num = 16;
}else if (displaysize = = 1080) {num = 20;
} float[] outerradii = new float[] {0, 0, num, num, 0, 0, num, num};
Shapedrawable timeview_shapedrawable = new shapedrawable ();
Timeview_shapedrawable.setshape (New Roundrectshape (outerradii, NULL, NULL));
Timeview_shapedrawable.getpaint (). SetColor (Color.argb (255, 255, 255, 255));
Timeview.setbackgrounddrawable (timeview_shapedrawable);
Asynchronous execution countdown//Asynchronously load ad picture new Showpopadtask (context, Pop_layout, Timeview). Execute ();
New Timecountdowntask (Timeview, Time). Execute ();
TextView TextView = new TextView (context);
Textview.setlayoutparams (New Linearlayout.layoutparams (Layoutparams.fill_parent, Layoutparams.fill_parent, 5f));
Textview.settext ("Starting, please later ...");
Textview.setgravity (Gravity.center); Textview.settextcolor (Color.White);
L_layout.addview (pop_layout);
Layout.addview (l_layout);
Layout.addview (TextView);
return layout;
Private class Timecountdowntask extends Asynctask<void, Void, boolean>{TextView Timeview;
int limit_time = 0;
Timecountdowntask (TextView timeview, int time) {This.timeview = Timeview;
This.limit_time = time; @Override protected Boolean doinbackground (Void ... params) {while (Limit_time > 0) {mhandler.post (New Runnable (
{@Override public void run () {Timeview.settext ("remaining" + Limit_time + "seconds");
}
});
try {thread.sleep (1000);
catch (Exception e) {e.printstacktrace ();
} limit_time--;
return null;
} private class Showpopadtask extends Asynctask<void, Void, boolean>{context;
Relativelayout pop_layout;
LinearLayout Popadview;
TextView Timeview;
int height_full = 0;
int height = 0;
Showpopadtask (context, Relativelayout pop_layout, TextView timeview) {this.context = context; this.pop_lAyout = Pop_layout;
This.timeview = Timeview; @Override protected Boolean doinbackground (Void ... params) {try {height_full = (activity) context). Getwindowmana
Ger (). Getdefaultdisplay (). GetHeight ();
int height_tmp = height_full-75;//75 height for device status bar plus title bar = height_tmp * 5/6; while (true) {if ((activity) context). Getresources (). GetConfiguration (). Orientation = = Configuration.orientation_ Landscape && height_full <=) {Popadview = appconnect.getinstance (context). Getpopadview (Context, Heigh
T, height);
}else{Popadview = appconnect.getinstance (context), getpopadview (context); } if (Popadview!= null) {Mhandler.post (new Runnable () {@Override public void run () {Pop_layout.addview (
Popadview);
Popadview.setid (1); Countdown to the layout of the required layoutparams relativelayout.layoutparams params = new Relativelayout.layoutparams (LAYOUTPARAMS.WRAP_
CONTENT, layoutparams.wrap_content); Params.addrule (Relativelayout.align_top, Popadview.getid ());
Params.addrule (Relativelayout.align_right, Popadview.getid ());
Screen judgment of the mobile phone int displaysize = sdkutils.getdisplaysize (context);
if (displaysize =) {params.topmargin=1;
Params.rightmargin=1;
}else if (displaysize = =) {params.topmargin=1;
Params.rightmargin=1;
}else if (displaysize = = 720) {params.topmargin=3;
params.rightmargin=3;
}else if (displaysize = = 1080) {params.topmargin=4;
params.rightmargin=4;
}else{params.topmargin=2;
params.rightmargin=2;
} pop_layout.addview (Timeview, params);
}
});
Break
try {thread.sleep (500);
catch (Interruptedexception e) {e.printstacktrace ();
A catch (Exception e) {e.printstacktrace ());
return null;
}
}
}