alamkanak / Android-Week-View

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
Apache License 2.0
3.42k stars 1.23k forks source link

24-hours day: fit to screen #168

Open sergiiz opened 9 years ago

sergiiz commented 9 years ago

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

datikaa commented 8 years ago

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

entropitor commented 8 years ago

@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).

obaslan commented 8 years ago

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?

entropitor commented 8 years ago

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 :)