Android-Week-View icon indicating copy to clipboard operation
Android-Week-View copied to clipboard

24-hours day: fit to screen

Open sergiiz opened this issue 11 years ago • 4 comments

Is it possible to scale calendar day height to make all 24 hours to fit the screen? Or even better, to make only business hours fit the screen?

Now I found the way how to do it if set proper height of each hour like in xml: app:hourHeight="20dp", but obviously it is a hardcode approach which can't be applied for all devices screen sizes

image

sergiiz avatar Aug 23 '15 21:08 sergiiz

Hi there! I managed to get something you want with this code:

weekView.post(new Runnable() {
            @Override
            public void run() {
                int height = weekView.getHeight();
                int textSize = weekView.getTextSize();
                int padding = weekView.getHeaderRowPadding();
                height = height - textSize - (2 * padding);
                weekView.setHourHeight(height / 24);
            }
        });

Note that as I tested it only works in activity's onCreate() method. I wanted to ultimately use it in a fragment, but I always get exceptions because I call getHeight() sooner than it is measured gettint a negative size. Also note thate it will still support scrolling, therefore it will be a bit jumpy when it recognizes vertical scroll. But I also would really love to have this feature built in.

Edit: for clarification; my code is nowhere near a perfect solution

datikaa avatar Nov 20 '15 12:11 datikaa

@sergiiz What if you set the hourheight to 0 or 1 or so? I think (at least in the new version that will be out soon, that should work, but I haven't tested it yet).

entropitor avatar Nov 20 '15 17:11 entropitor

In the current version, zooming is possible so this issue is partially solved. @caske33 did you realize that when you are fully zoomed out, you can still scroll up-down a little bit? Is there an easy fix for that?

obaslan avatar Jan 03 '16 19:01 obaslan

I'm guessing the calculation is then wrong and we need to fix that. (We might have missed a padding or something).

The library is rather simple so it should be simpel to get into it. Feel free to fix this and sent over a Pull Request. I'll be happy to merge it :)

entropitor avatar Jan 03 '16 21:01 entropitor