0

I have a situation where I'm manually adjusting a WebView's dimensions onMeasure because I need the webview to be square and to occupy a specific percentage of the screen (and appear at some specific relative coordinate after it's been shaped into the square). The webview does appear to be shaped correctly and resides on the screen where I intend for it to be (I'm using setX() and setY(), however I'm finding that the sibling TextViews don't then relocate to where they should normally be, based on their relative positioned relationships to the WebView.

In other words, they are placed based on the original WebView's shape and position, and when the WebView is resized, they stay put.

Is there something else I need to do to have Android move them into place based on the repositioned WebView? Or do I have to manually maneuver and shape them as well?

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236

1 Answers1

1

You should change the size and shape using LayoutParams:

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);
Phil
  • 35,852
  • 23
  • 123
  • 164