2017-04-27 66 views
0

我想要水平滾動一些數字(0-23)作爲它的項目水平listview。降低水平列表視圖的高度 - xamarin表格

我得到的列表視圖是水平的,但listview的高度沒有被包裝到內容。我試着用xConstraint,yConstraint,width和heightConstraint使用RelativeLayout,我試着改變它的參數值,但是listview消失了所有的時間我改變了值。

ListView lv = new ListView 
     { 
      SeparatorVisibility = SeparatorVisibility.None, 
      ItemsSource = items, 
      Rotation = 270, 

      ItemTemplate = new DataTemplate(() => 
      { 

       Label label = new Label() 
       { 
        Rotation = 90, 
        TextColor = Color.Black, 
        HorizontalTextAlignment = TextAlignment.Center, 
        FontSize = Device.GetNamedSize(NamedSize.Small, new Label()) 
       }; 
       label.SetBinding<User>(Label.TextProperty, indexer => indexer.Time); 

       return new ViewCell 
       { 
        View = new StackLayout 
        { 
         Children = 
          { 
          label 
         } 
        } 
       }; 
      }) 
     }; 

     RelativeLayout rLayout = new RelativeLayout(); 

     rLayout.Children.Add(lv, 
          xConstraint: Constraint.RelativeToParent((parent) => 
           { 
            return (parent.Width/0.5) - 30; 
           }), 
          yConstraint: Constraint.RelativeToParent((parent) => 
           { 
            return (parent.Height/-0.5) + 3; 
           }), 
          widthConstraint: Constraint.Constant(60), 
          heightConstraint: Constraint.RelativeToParent((Parent) => 
           { 
            return (Parent.Height/10); 
           }) 
     ); 

     Content = new StackLayout 
     { 
      Children = { 
       rLayout 
      } 
     }; 

我是新來的xamarin,可能是我走的路是錯誤的。如果是這樣,請建議我正確的一個..但總的來說,我想要一個水平的listview只有數字作爲項目,我想高度被包裹到內容。

請任何幫助,將提前可觀..感謝..

+0

對於這樣的簡單的場景我可能會使用'''內'。使用'ItemsSource'屬性創建基於'StackLayout'的自定義控件。 –

+0

也許你可以嘗試使用[carousel view](https://blog.xamarin.com/flip-through-items-with-xamarin-forms-carouselview/)。不太確定它是否適合您的使用案例。 –

+0

感謝您的回答@EgorGromadskiy它幫助我..對不起,最近的回覆.. – user5598997

回答

0

如果你想在列表視圖中的項目自動高度,那麼你必須在你的XAML文件中使用HasUnevenRow="true"

實施例:

<ListView x:Name="SomeList" HasUnevenRows="True" ItemsSource="{Binding ...}" SeparatorVisibility="None"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
      <ViewCell> 
       <ViewCell.View> 
       <Label HorizontalOptions="CenterAndExpand" TextColor="Blue" Margin="0,5,0,5" Text="{Binding ....}" FontSize="Small" HeightRequest="35"/> 
       </ViewCell.View> 
      </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
     </ListView> 
+0

感謝您的回覆Prabhat ..我試過,但結果是一樣的解釋在我的問題.. – user5598997