Search code examples
androidscreen-resolutionandroid-viewgroupandroid-framelayout

how to add childviews dynamically to layout based on screen resolution


I have a layout with screen resolution,

public static int height = Resources.getSystem().getDisplayMetrics().heightPixels;
    public static int width =Resources.getSystem().getDisplayMetrics().widthPixels;

now I want to add multiple childviews to that layout based on its height and width

I know how to add views but wanted to get the count of views that can be added and remaining will be shown in next page


Solution

  • You will just have to calculate it based on the dimensions you have. So get divide the height of your parent view by the height of the child view and you get the number of views that fit in that parent. Use a floor function to make sure you have a nice rounded number to work with.