@Test public void shouldReturnPreviouslySetLayoutParams() { assertThat(webView.getLayoutParams()).isNull(); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); webView.setLayoutParams(params); assertThat(webView.getLayoutParams()).isSameAs(params); }
WebView webview = (WebView)findViewById(R.id.webview); MarginLayoutParams marginsParams = new MarginLayoutParams(webview.getLayoutParams()); marginsParams.setMargins(50, 50,1024-50, 600-50); RelativeLayout.LayoutParams lp = new LayoutParams(marginsParams); webview.setLayoutParams(lp);
WebView w =new WebView(this); LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); w.setLayoutParams(lp); w.getLayoutParams().width = 200; w.getLayoutParams().height = 200; ( (ViewGroup) insertPoint ).addView(w) ;
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); WebView mWebView = (WebView) findViewById(R.id.myWebView); ViewGroup.LayoutParams params = mWebView.getLayoutParams(); params.width = screenWidth*3/4;//or whatever you need, relative to the screen size params.height = screenHeight*3/4; //you can also add margins programmatically here, which may be better than using setX/setY mWebView.setLayoutParams(params);
final WebView wv = new WebView(main); new AsyncTask<Void,Void,Void>(){ @Override protected Void doInBackground(Void... params) { try { Thread.sleep(2000); } catch (InterruptedException ex){ ex.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { mainLayout.addView(wv); LayoutParams params = wv.getLayoutParams(); // Edit those params as you need, then call wv.setLayoutParams(params); } }.execute();
static public void setImageDimensions(ThreadViewHolder viewHolder, Point targetSize) { //ViewGroup.LayoutParams params = viewHolder.list_item_image_expanded.getLayoutParams(); if (DEBUG) Log.i(TAG, "setImageDimensions() to " + targetSize.x + "x" + targetSize.y); if (viewHolder.list_item_image_expanded_click_effect != null) { ViewGroup.LayoutParams params2 = viewHolder.list_item_image_expanded_click_effect.getLayoutParams(); if (params2 != null) { params2.width = targetSize.x; params2.height = targetSize.y; } } if (viewHolder.list_item_image_expanded_webview != null) { ViewGroup.LayoutParams params3 = viewHolder.list_item_image_expanded_webview.getLayoutParams(); if (params3 != null) { params3.width = targetSize.x; params3.height = targetSize.y; } } if (viewHolder.list_item_image_expanded_wrapper != null) { ViewGroup.LayoutParams params4 = viewHolder.list_item_image_expanded_wrapper.getLayoutParams(); if (params4 != null) { //params3.width = params.width; always match width params4.height = targetSize.y; } } }
int height = width * options.outHeight / options.outWidth; ViewGroup.LayoutParams layoutParams = webView.getLayoutParams(); layoutParams.width = width; layoutParams.height = height;
ViewGroup.LayoutParams spaceParams = webViewSpace.getLayoutParams(); ViewGroup webViewSpaceParent = ((ViewGroup) webViewSpace.getParent()); int index = webViewSpaceParent.indexOfChild(webViewSpace);