Created
July 15, 2014 07:03
-
-
Save akbarsha03/1c8a677b401bad693038 to your computer and use it in GitHub Desktop.
Get required view size dynamically in percentage depends upon the Screen size
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
/** | |
* Get the area of the screen size. following calculation done with the help | |
* of Ashik :D | |
* | |
* @param context | |
* @param percentage | |
* @return intRequiredCellSize | |
* @author Ashik Ali | |
*/ | |
public static int getCellSizeForScreen(Context context, double percentage) { | |
WindowManager wm = (WindowManager) context | |
.getSystemService(Context.WINDOW_SERVICE); | |
Display display = wm.getDefaultDisplay(); | |
DisplayMetrics metrics = new DisplayMetrics(); | |
display.getMetrics(metrics); | |
int width = metrics.widthPixels; | |
int height = metrics.heightPixels; | |
/** | |
* Calculate the percentage of the current_screen_area. 0.01 represents | |
* the percentage of the cell size in the total percentage of the screen | |
* size | |
*/ | |
int required_squre_area = (int) ((height * width) * (percentage / 100)); | |
int required_squre_size = (int) Math.sqrt(required_squre_area); | |
return required_squre_size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment