【问题标题】:Xamarin forms Label going out of View Inside StackLayoutXamarin 表单标签在 StackLayout 内的视图中消失
【发布时间】:2019-02-08 11:10:19
【问题描述】:

我正在尝试在 stacklayout 中放置一个标签...行数可能会根据数据而变化...但是当文本更多时标签会消失,它不会扩展...

<StackLayout Orientation="Vertical" 
                              BackgroundColor="White"
                              VerticalOptions="FillAndExpand"
                      Spacing="0"> 

                <StackLayout Orientation="Vertical" BackgroundColor="Silver"
                             HeightRequest="45">
                    <AbsoluteLayout BackgroundColor="White"
                HorizontalOptions="FillAndExpand"
                HeightRequest="44"
                                    Margin="0.5"
                VerticalOptions="StartAndExpand"
                >
                  <Label Text="Objective"
                         Margin="15,0,0,0"
                         AbsoluteLayout.LayoutBounds="0,0.5,-1,-1" 
                    AbsoluteLayout.LayoutFlags="PositionProportional"
                         VerticalTextAlignment="Center"
                         FontFamily="Roboto#300" FontSize="16" FontAttributes="None" TextColor="#FF888888" />

                    <Button HeightRequest="32" Margin="0,0,15,0"
                             WidthRequest="32"
                            Padding="0"

                            x:Name="ObjectiveButton"
                            Clicked="Objective_Button_Handle_Clicked"
                      BackgroundColor="Transparent"
                              AbsoluteLayout.LayoutBounds="1,0.5,-1,-1" 
                        AbsoluteLayout.LayoutFlags="PositionProportional"
                            Image="collapseIcon.png"/>




                  </AbsoluteLayout>

                </StackLayout>


                <StackLayout Orientation="Vertical"
                             BackgroundColor="White"
                             x:Name="ObjectiveStackLayout"
                             VerticalOptions="CenterAndExpand"

                             IsVisible="true" >

                   <Label Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
                            sed do eiusmod tempor incididunt ut
                            labore et dolore magna aliqua.
                            Ut enim ad minim veniam, 
                            quis nostrud exercitation ullamco
                            laboris nisi ut aliquip ex ea
                            commodo consequat."
                          FontFamily="Roboto#400"
                          FontSize="14"
                          VerticalTextAlignment="Center"
                           Margin="15,10,0,0"
                          MaxLines="0"
                          LineBreakMode="WordWrap"
                          FontAttributes="None"
                          TextColor="#FF858585" />




                </StackLayout>

                </StackLayout>

【问题讨论】:

    标签: xaml xamarin.forms


    【解决方案1】:

    所以最后我使用 Grid 解决了这个问题......我没有将根视图作为 StackLayout,而是将其作为 Grid。如果我们为行高设置 Auto 属性。标签大小是根据其内容确定的。

    【讨论】:

      【解决方案2】:

      您要问的是堆栈布局中标签的默认行为,前提是您允许它。

      我不明白你想用 MaxLines 做什么,这里你要求在标签中显示 0 行文本,根本不应该显示任何内容。

      你只需要去掉 MaxLines 属性,这样标签就可以根据它自己的内容进行调整。

      要么这样,要么我没有得到你想要做的事情。

      【讨论】:

        猜你喜欢
        • 2021-12-07
        • 1970-01-01
        • 2020-11-14
        • 2018-01-19
        • 2016-09-07
        • 2020-03-21
        • 1970-01-01
        • 2020-04-20
        • 2019-04-02
        相关资源
        最近更新 更多