代码之家  ›  专栏  ›  技术社区  ›  Kajot

水平和垂直中间的Xamarin列表视图项文本不工作

  •  0
  • Kajot  · 技术社区  · 5 年前

    所以我有一个列表视图,我不能让文本在水平和垂直中间。

    我试过这个:

                        <ListView x:Name="EssenListView" 
                        ItemsSource="{Binding EssenAnTag}"
                        Footer=""
                        SeparatorVisibility="None"
                        VerticalOptions="FillAndExpand"
                        HorizontalOptions="FillAndExpand"
                        HasUnevenRows="true"
                        RefreshCommand="{Binding EssenLadenCommand}"
                        IsPullToRefreshEnabled="true"
                        IsRefreshing="{Binding Laedt, Mode=OneWay}"
                        ItemSelected="EssenGewaehlt">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <ViewCell.View>
                                        <StackLayout>
                                            <StackLayout HorizontalOptions="FillAndExpand" HeightRequest="65" BackgroundColor="{Binding BackgroundColor}">
                                                <Label Text="{Binding Ausgabe}" 
                                                    FontSize="18"
                                                    HorizontalOptions="Center"
                                                    VerticalOptions="Center"
                                                    LineBreakMode="WordWrap" />
                                            </StackLayout>
                                            <Label HeightRequest="15" BackgroundColor="White"/>
                                        </StackLayout>
                                    </ViewCell.View>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
    

    如下图所示,如果文本很小,则至少水平居中,但如果文本很长,并且完全不居中。 enter image description here

    2 回复  |  直到 5 年前
        1
  •  0
  •   Cherry Bu - MSFT    5 年前

    在标签控件中添加HorizontalTextAlignment=“Center”属性,如下所示:

                                      <Label Text="{Binding Ausgabe}" 
                                                FontSize="18"
                                                HorizontalOptions="Center"
                                                HorizontalTextAlignment="Center"
                                                VerticalOptions="Center"
                                                LineBreakMode="WordWrap" />
    
        2
  •  0
  •   Ataberk Uzkal    5 年前

    使用 HorizontalTextAlignment="Center" 对齐标签中的文本。

    HorizontalOptions="Center" 对齐标签本身。