文字を横に流すアレです
iOSとAndroidのエミュで動作確認済み
#Xamarin で Ticker的なのを作った pic.twitter.com/JLn0CS65q4
— 吉田カエル@長崎 (@Frog_woman) 2018年5月17日
<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
の部分が合ってるのかがよく分かりません。
何か良い書き方などが他にありましたら教えて下さい。