如何使标签文本自动滚动?

时间:2019-07-28 03:00:53

标签: c# xamarin.forms marquee

我有一个按钮,需要输入一些文本,但是某些文本可能太长,无法很好地适合按钮。我想使文本像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);
}

我希望整个文本从右向左移动并重复,而不离开按钮的边界。

1 个答案:

答案 0 :(得分:0)

您可以检查一下,是否是您需要的效果?

<script>
  function addToRoom(i) {
    $addButton = document.getElementById("roomButton" + i);

    if ($addButton.innerHTML == "+") {
      $addButton.innerHTML = "-";
      $addButton.classList.remove("roomAddButton");
      $addButton.classList.add("roomRemoveButton");
    }
}
</script>