A utility class for dynamically setting view object height and width based on percentages of the total screen height and width.
This has saved me a lot of time creating layouts that look good across different screen sizes, but it doesn't look very good on larger devices such as tablets.
##Using this class
- Add the class to your package and change the package line at the top:
package com.my.package;
- Create an instance of this class:
ScreenUtility utility = new ScreenUtility(this);
(We need to pass the current activity to it in the constructor)
- Declare your view objects, for example a button:
Button myButton = (Button)findViewById(R.id.mybutton);
- Set its dimensions!
int width = 100;
int height = 20;
utility.setViewObjectDimensionsAsPercentage(height, width, myButton);
The view object will now be the size you gave it, in percentage, of the total height and width of the screen size.