如何在Range Seek Bar中显示时间格式?

时间:2017-09-14 09:26:11

标签: android android-seekbar

我想在我的sek栏中放置2个drawables。首先是最小时间,第二个drawable将显示用户选择的最长时间。为此,我使用THIS LIBRARY.但没有运气。我怎样才能得到我想要的结果?我在这做了什么。

[assembly: ExportRenderer(typeof(ExtendedTabbedPage), typeof(ExtendedTabbedPageRenderer))]
namespace ExtendedTabbedPage.Pages
{
    public class ExtendedTabbedPageRenderer : TabbedRenderer
    {
        private ExtendedTabbedPage Page => (ExtendedTabbedPage)Element;
    public ExtendedTabbedPageRenderer()
    {

    }

    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);

        var page = (ExtendedTabbedPage)Element;
        page.CurrentPageChanged += Page_CurrentPageChanged;

    }

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
        Page_CurrentPageChanged();
    }


    public override void ViewDidLayoutSubviews()
    {
        base.ViewDidLayoutSubviews();
        SetTabPostition();
    }

    void SetTabPostition()
    {
        if (Element == null)
            return;

        var element = Element as ExtendedTabbedPage;

        this.TabBar.InvalidateIntrinsicContentSize();

        nfloat tabSize = 74.0f;

        UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

        if (UIInterfaceOrientation.LandscapeLeft == orientation || UIInterfaceOrientation.LandscapeRight == orientation)
        {
            tabSize = 32.0f;
        }

        CGRect tabFrame = this.TabBar.Frame;
        CGRect viewFrame = this.View.Frame;

        tabFrame.Height = tabSize;
        tabFrame.Y = this.View.Frame.Y;
        this.TabBar.Frame = tabFrame;
        this.TabBar.ContentMode = UIViewContentMode.Top;

        PageController.ContainerArea = new Rectangle(0, tabFrame.Y + tabFrame.Height, viewFrame.Width, viewFrame.Height - tabFrame.Height);
        this.TabBar.SetNeedsUpdateConstraints();
    }

    void Page_CurrentPageChanged()
    {
        var current = Tabbed.CurrentPage;
        //if Tab is more than 5 then more will appear in iOS
        if (current == null)
        {
            CGRect tabFrm = this.TabBar.Frame;
            if (this.MoreNavigationController != null)
            {
                var morenavframe = this.MoreNavigationController.View.Frame;
                morenavframe.Y = tabFrm.Y + tabFrm.Height;
                this.MoreNavigationController.View.Frame = morenavframe;

                foreach (var morecontroller in this.MoreNavigationController.ViewControllers)
                {
                    var morecontframe = morecontroller.View.Frame;
                    morecontframe.Y = morenavframe.Y + morenavframe.Height;
                    morecontroller.View.Frame = tabFrm;
                }
            }
            return;
        }

        var controller = Platform.GetRenderer(current);
        if (controller == null)
            return;

        var frame = controller.ViewController.View.Frame;
        CGRect tabFrame = this.TabBar.Frame;
        frame.Y = (tabFrame.Y + tabFrame.Height);
        controller.ViewController.View.Frame = frame;
        this.View.Frame = frame;
    }


    public override void ViewDidAppear(bool animated)
    {
        base.ViewDidAppear(animated);
        Page_CurrentPageChanged();
    }
  }
}

1 个答案:

答案 0 :(得分:2)

要获得所需的结果,您必须将最短时间和最长时间转换为分钟。

String start[] = "6:00".split(":");
int min = Integer.parseInt(start[0]) * 60 + Integer.parseInt(start[1]);
String end[] = "23:49".split(":");
int max = Integer.parseInt(end[0]) * 60 + Integer.parseInt(end[1]);

rangeSeekBar.setSelectedMinValue(min);
rangeSeekBar.setSelectedMaxValue(max);

现在在

onRangeSeekBarValuesChanged(RangeSeekBar<Integer> bar, Integer minValue, Integer maxValue)
{
int minHour=minValu/60; //since both are ints, you get an int
int minMinute=minValu % 60;

int maxHour=maxValu/60; //since both are ints, you get an int
int maxMinute= maxValu % 60 ;
}