Created
May 26, 2019 16:31
-
-
Save alidaoud/19aa2cf151be5fc33357ea7a4684dfdc to your computer and use it in GitHub Desktop.
Set view width & height programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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