Gabriele Puia
Gabriele Puia

Reputation: 333

Set webview dimensions programmatically

I'm using a webview in my code, and I'm trying to set the dimensions via programmatically. Is there a way i can do it?

Upvotes: 0

Views: 583

Answers (1)

Akash Pal
Akash Pal

Reputation: 1115

You should use RelativeLayout instead

EXAMPLE:

Suppose you want a WebView of size (50, 60) on your screen at position (70, 80)

// RelativeLayout. though you can use xml RelativeLayout here too by `findViewById()`

RelativeLayout relativeLayout = new RelativeLayout(this);
// webView
WebView w= new WebView(this);
    w.setId(0X100);
    w.setScrollContainer(false);
// Setting layout params to our RelativeLayout
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(50, 60);

// Setting position of our ImageView
layoutParams.leftMargin = 70;
layoutParams.topMargin = 80;

// Finally Adding the imageView to RelativeLayout and its position
relativeLayout.addView(w, layoutParams);

Upvotes: 3

Related Questions