2017-07-02 37 views
0

目前我已經建立了使用下面的XAML的列表視圖Xamarin形式的細胞操縱RTL

<ListView x:Name="_lstMenu" VerticalOptions="FillAndExpand" BackgroundColor="Transparent"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" /> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
</ListView> 

我想要做的是當語言切換到阿拉伯語使得整個用戶體驗的右以左至右爲導向。爲了做到這一點,我使用了RotateYTo(180)方法。

protected override void rotateElementsY(int rotationY) 
{ 
    base.rotateElementsY(rotationY); 

    foreach (View sub in subviews()) 
    { 
     sub.RotateYTo(rotationY); 
    } 
} 

private View[] subviews() 
{ 
    View[] _subs = new View[] { 
     imgUser, lblGreetings, lblUserName, lstMenu, stkBottom}; 
    return _subs; 
} 

它運作良好,到目前爲止,除了的ImageCell因爲我只能在左到右的方向,以顯示它而已,而不能轉動任何Cell的孩子的的(標籤,圖像) 。 PS:我也嘗試在鏡像列表視圖後反過來寫單元格的阿拉伯文字,但它看起來不合適。

回答

1

感謝ganchito55激發我對我需要的答案。我非常習慣了製作RTL的想法,但是在需要時也可以轉換爲LTR。

<ListView x:Name="_lstMenu" VerticalOptions="FillAndExpand" BackgroundColor="Transparent"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <Grid> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="2*"/> 
          <ColumnDefinition Width="6*"/> 
          <ColumnDefinition Width="2*"/> 
         </Grid.ColumnDefinitions> 
         <Image Source="{Binding IconSource}" IsVisible="{Binding isEnglish}"/> 
         <Label Grid.Column="1" Text="{Binding Title}" VerticalTextAlignment="Center" HorizontalTextAlignment="{Binding alignment}"/> 
         <Image Grid.Column="2" Source="{Binding IconSource}" IsVisible="{Binding isArabic}"/> 
        </Grid> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
</ListView> 

正如你可以看到我已經增加了一個形象的項目模板和屬性,以列出的項目對象來決定顯示每次使用的形象和定位。

1

我認爲,對RTL語言的最佳解決方案是創建一個自定義單元格時,你有在右邊的圖像,然後用右對齊的標籤,例如:

<ListView 
    x:Name="_lstMenu" 
    BackgroundColor="Transparent" 
    VerticalOptions="FillAndExpand"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell> 
       <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="4*" /> 
         <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 
        <Label 
         HorizontalTextAlignment="End" 
         Text="{Binding Title}" 
         VerticalTextAlignment="Center" /> 
        <Image Grid.Column="1" Source="{Binding Image}" /> 
       </Grid> 
      </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

我希望這能幫你。