Code example for RelativeLayout

Methods: setLayoutParamsaddView

    // add WebView to a layout (for the map legend) 
    public static void addWebView(RelativeLayout mainLayout, Activity activity, String html){
     // first container layout 
     RelativeLayout legendLayout = new RelativeLayout(activity);
     RelativeLayout.LayoutParams legendLayoutparams = 
             new RelativeLayout.LayoutParams(320, 300);
     legendLayoutparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
     legendLayoutparams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
     legendLayoutparams.setMargins(15, 15, 0, 0);
     // now create the webview itself, and add to legendView 
     WebView webView = new WebView(activity);
     // force to open any URLs in native browser instead of WebView  
     webView.setWebViewClient(new WebViewClient() {
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
              return super.shouldOverrideUrlLoading(view, url);
     webView.layout(0, 0, 320, 300);
     webView.loadDataWithBaseURL("file:///android_asset/",HTML_HEAD+html+HTML_FOOT, "text/html", "UTF-8",null);
Stop searching for code, let great code find you!  Add Codota to your java IDE