|
Telas

Projeto

IInfo.cs
using System;
namespace VisualTeste
{
public interface IInfo
{
int GetLargura { get; }
int GetAltura { get; }
}
}
VisualTeste.cs
using System;
using Xamarin.Forms;
namespace VisualTeste
{
public class App : Application
{
public static int ScreenWidth;
public static int ScreenHeight;
ProgressBar pb;
public App ()
{
// largura da tela
int largura = DependencyService.Get<IInfo>().GetLargura;
pb = new ProgressBar ();
pb.HorizontalOptions = LayoutOptions.CenterAndExpand;// FillAndExpand;
pb.WidthRequest = largura - (largura / 10);
Button bt = new Button { Text = "Clique me" };
bt.Clicked += OnClicked;
StackLayout layoutHorz = new StackLayout ();
layoutHorz.HorizontalOptions = LayoutOptions.Center;
layoutHorz.Children.Add (pb);
layoutHorz.Children.Add (bt);
ContentPage pag = new ContentPage ();
pag.Content = layoutHorz;
MainPage = pag;
}
void OnClicked (object sender, EventArgs e)
{
pb.Progress += pb.Progress + 0.1;
}
}
}
Info.cs
using System;
using Android.Util;
using Xamarin.Forms;
using VisualTeste.Droid;
using Android.Content.Res;
[assembly: Dependency (typeof (Info))]
namespace VisualTeste.Droid
{
public class Info : IInfo
{
public int GetLargura {
get {
return Resources.System.DisplayMetrics.WidthPixels; // real pixels
}
}
public int GetAltura {
get {
return Resources.System.DisplayMetrics.HeightPixels; // real pixels
}
}
}
}
|