2017-04-27 68 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