我必须给定项目的动态数平分在屏幕上(如可能的话)。
所以,我需要找到基于屏幕尺寸/比列和行数。
每个项目的大小并不重要,因为我会在%进行每山口和行项目计算它们。
如果我有5个项目,则(根据屏幕比率)1将可能有第一行中的3列和第2行中的2列。 没关系。
我必须给定项目的动态数平分在屏幕上(如可能的话)。
所以,我需要找到基于屏幕尺寸/比列和行数。
每个项目的大小并不重要,因为我会在%进行每山口和行项目计算它们。
如果我有5个项目,则(根据屏幕比率)1将可能有第一行中的3列和第2行中的2列。 没关系。
首先,你必须决定你的意思是用“分同样的屏幕”是什么。 这可能意味着,有一个优选的的x到-Y比为每个项目。
您可以使用下面的算法有利于在减少空余空间的数量越来越接近需要的x-到-Y比。
// Set this to the desired x-to-y ratio.
const preferred_ratio = 1.2;
function calc_cols_rows(In: screen, In: num_items, Out: num_rows, Out: num_cols) {
desired_aspect = (screen.width / screen.height) / preferred_ratio;
// Calculate the number of rows that is closest to the desired aspect:
num_rows = round(sqrt(num_items / desired_aspect));
// Calculate the required number of columns:
num_cols = ceil(num_items / num_rows);
}