1. 程式人生 > >xamarin.form absolutelayout和Device.StartTimer

xamarin.form absolutelayout和Device.StartTimer

<ContentPage.Content>
        <AbsoluteLayout>
            <BoxView BackgroundColor="Red" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
            </BoxView>
            <BoxView BackgroundColor="White" AbsoluteLayout.LayoutBounds="0.5,0.5,100,100" AbsoluteLayout.LayoutFlags="PositionProportional"></BoxView>
            <BoxView BackgroundColor="Blue" AbsoluteLayout.LayoutBounds="0,1,1,100" AbsoluteLayout.LayoutFlags="PositionProportional,WidthProportional"></BoxView>
        </AbsoluteLayout>
    </ContentPage.Content>

 

            AbsoluteLayout abs = new AbsoluteLayout();
            {
                BoxView b = new BoxView() { BackgroundColor = Color.Red };
                AbsoluteLayout.SetLayoutBounds(b, new Rectangle(0, 0, 1, 1));
                AbsoluteLayout.SetLayoutFlags(b, AbsoluteLayoutFlags.All);
                abs.Children.Add(b);
            }
            {
                BoxView b = new BoxView() { BackgroundColor = Color.White };
                AbsoluteLayout.SetLayoutBounds(b, new Rectangle(0.5, 0.5, 100, 100));
                AbsoluteLayout.SetLayoutFlags(b, AbsoluteLayoutFlags.PositionProportional);
                abs.Children.Add(b);
            }
            {
                BoxView b = new BoxView() { BackgroundColor = Color.Blue };
                AbsoluteLayout.SetLayoutBounds(b, new Rectangle(0, 1, 1, 60));
                AbsoluteLayout.SetLayoutFlags(b, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);
                abs.Children.Add(b);
            }
            this.Content = abs;

   

AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"
其中AbsoluteLayout.LayoutBounds="0,0,1,1"代表X,Y,寬度,高度AbsoluteLayout.LayoutFlags="All"代表狂傲和Xy是以百分比的形式還是以畫素點的形式顯示,ALL代表全部都是百分比的形式
ALL代表所有的XY寬高都是以百分比的形式
PositionProportional代表XY是以百分比的形式
WidthProportional 代表寬度是以百分比的形式
None 代表所有的都不是以百分比的形式

HeightProportional 代表高度是以百分比的形式
XProportional 代表X軸是以百分比的形式
YProportional 代表Y周是以百分比的形式
SizeProportional 代表大小是以百分比的形式
 
 
 
<ContentPage.Content>
        <AbsoluteLayout>
            <Image Source="http://i1.umei.cc/uploads/tu/201811/9999/b21a1c8366.jpg" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">                
            </Image>
            <BoxView BackgroundColor="Black" Opacity="0.5" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"></BoxView>
            <ActivityIndicator IsRunning="True" Color="White" AbsoluteLayout.LayoutBounds="0.5,0.5,0.1,0.1" AbsoluteLayout.LayoutFlags="All"></ActivityIndicator>
        </AbsoluteLayout>
    </ContentPage.Content>

  

in      int sleepsecount = int.MaxValue;
        int waitsecount = 0;
        public MainPage()
        {
            InitializeComponent();
            Device.StartTimer(TimeSpan.FromSeconds(1), () =>
            {
                this.label1.Text = waitsecount.ToString();
                return waitsecount++ < sleepsecount;
            });
        }