The essence of the problem: There is an array of subtitles (long start, long end, string text). I need to change the width (int) for the corresponding item in RecyclerView depending on the display time. If the end and the beginning of the next one do not coincide in time, then I add an empty element between them.
subs.add(new Subtitle(subtitles.get(i - 1).getEnd(), subtitles.get(i).getStart(), "")); secInPx = 50; - number of pixels per 1 second of time. At first I tried to do this:
int width = (int) ((end - start)*secInPx)/1000 on each subtitle there will be a loss of fractions of pixels. For 45 minutes of video (approximately 2000 subtitles) I get an offset of about 400 pixels.
then I decided to add to the next element everything that was lost earlier. rvWidth - the width of the RecyclerView,
rvWidth = (videoDuration / 1000) * Constant.secInPx; for (int i = 0; i < subtitles.size(); i++) { widthSums.add((int) ((subtitles.get(i).getEnd()*rvWidth)/videoDuration)); } subtitles.get(0).setWidth(widthSums.get(0)); for (int i = 1; i < subtitles.size(); i++) { subtitles.get(i).setWidth(widthSums.get(i) - widthSums.get(i-1)); } now we get an offset of about 30 pixels, the same 45 minutes, 2000 subtitles.
How can you even more accurately determine the width of the elements?
The red lines are where the show should start and the end of the subtitles "did the allfather"
floatordouble? The division of a priori has an error, discarding the remainder. - woesss