Skip to content

Instantly share code, notes, and snippets.

@alidaoud
Created May 26, 2019 16:31
Show Gist options
  • Select an option

  • Save alidaoud/19aa2cf151be5fc33357ea7a4684dfdc to your computer and use it in GitHub Desktop.

Select an option

Save alidaoud/19aa2cf151be5fc33357ea7a4684dfdc to your computer and use it in GitHub Desktop.
Set view width & height programmatically
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point(); //we're using this because the display.getWidth() is deprecated
display.getSize(size);
int viewWidth = size.x / 2;
int viewHeight = size.y / 3;
View ourView = findViewById(R.id.our_view_id);
ourView.setLayoutParams(new FrameLayout.LayoutParams(viewWidth,viewHeight));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment