我有一个按钮,我想要一些文本,但有些文本可能太长,无法很好地适应按钮。我想让文本在一行中水平滚动,就像HTML中的字幕一样。我可以让它在一行中滚动,然而,测试文本在按钮的边缘被截断,并且那里的文本实际上会从按钮上移动,而不是在按钮的边缘消失。
我已经在谷歌上搜索了我的问题的答案,几个小时后,我想是时候问我的问题了。
<Grid HeightRequest="400" Grid.Column="0" Grid.Row="0" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button BackgroundColor="#006633" Opacity="0.7" Grid.RowSpan="3" Grid.ColumnSpan="1">
</Button>
<Label x:Name="Label1" StyleClass="button" Grid.Row="1" Grid.Column="0" >
</Label>
</Grid>
public void Marque1()
{
Label1.Text = "This is to simulate a really long sentence for testing purposes";
Label1.HorizontalOptions = LayoutOptions.Start;
Label1.VerticalTextAlignment = TextAlignment.Center;
Label1.LineBreakMode = LineBreakMode.NoWrap;
Label1.TranslateTo(-50, 0, 8000, Easing.Linear);
}我希望整个文本从右向左移动并重复,而不是离开按钮的边界。
发布于 2019-07-29 16:01:26
你可以检查这个,它是你需要的效果:
public partial class MaqueText : ContentPage
{
private bool Execute { get; set; }
public MaqueText ()
{
InitializeComponent ();
Label1.Text = "This is to simulate a really long sentence for testing purposes";
Label1.HorizontalOptions = LayoutOptions.Start;
Label1.VerticalTextAlignment = TextAlignment.Center;
Label1.LineBreakMode = LineBreakMode.NoWrap;
}
protected override void OnAppearing()
{
base.OnAppearing();
Execute = true;
Device.StartTimer(TimeSpan.FromMilliseconds(50), () =>
{
Label1.TranslationX -= 5f;
if (Math.Abs(Label1.TranslationX) > Width)
{
Label1.TranslationX = Label1.Width;
}
return Execute;
});
}
protected override void OnDisappearing()
{
base.OnDisappearing();
Execute = false;
}
}https://stackoverflow.com/questions/57237615
复制相似问题