LoginSignup
1
0

More than 5 years have passed since last update.

Xamarin.FormsでTicker的なものを作ってみた

Last updated at Posted at 2018-05-17

文字を横に流すアレです

iOSとAndroidのエミュで動作確認済み

<ContentView BackgroundColor="Gray" HorizontalOptions="FillAndExpand">
    <AbsoluteLayout>
        <Label x:Name="label" TextColor="White" FontAttributes="Bold"/>
    </AbsoluteLayout>
</ContentView>
private double _count;

public MainPage()
{
    InitializeComponent();
}

protected override void OnSizeAllocated(double width, double height)
{
    base.OnSizeAllocated(width, height);

    //デバイズサイズを代入。右から左に流すので最大値からデクリメントさせていく
    _count = width;

    //文字サイズ
    int LabelFontSize = 25;

    //表示する文字
    String ViewText = string.Format("Width={0} Height={1}", Width, Height);
    //表示文字を代入
    label.Text = ViewText;
    //文字サイズ決定
    label.FontSize = LabelFontSize;

    double LabelWidth = ViewText.Length * LabelFontSize ;//文字数×1文字分のピクセル(合ってる?

    //Console.WriteLine("LabelWidth: {0} ", LabelWidth);

    Device.StartTimer(
    TimeSpan.FromSeconds(0.01),
    () =>
    {
        _count--;           
        AbsoluteLayout.SetLayoutBounds(this.label, new Rectangle(_count, 10, LabelWidth, 30));

        //Console.WriteLine("Count: {0} , position: {1}", _count, -LabelWidth);
        if(_count < -LabelWidth){
            _count = width;
        }
        return true;
    });
}

double LabelWidth = ViewText.Length * LabelFontSizeの部分が合ってるのかがよく分かりません。
何か良い書き方などが他にありましたら教えて下さい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0