2017-04-27 12 views
0

水平リストビューを水平方向にスクロールさせ、いくつかの数字(0〜23)をアイテムとして取得しようとしています。水平リストビューの高さを小さくする - xamarinフォーム

私はリストビューを水平にしていますが、リストビューの高さはコンテンツにラップされていません。 RelativeLayoutをxConstraint、yConstraint、width、およびheightConstraintで使用しようとしましたが、パラメータ値を変更しようとしましたが、リストビューは値を変更するたびに消えます。私はxamarinに新しいです

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 
      } 
     }; 

は、私が間違っているつもりな方法かもしれません。もしそうなら、私には正しいものを教えてください。しかし、全体としては、項目として数字だけを持つ水平のリストビューが必要であり、その高さをコンテンツにラップする必要があります。

任意のヘルプを事前に感謝..かなりのだろうしてください。..

+0

。 'ItemsSource'プロパティで' StackLayout'に基づいてカスタムコントロールを作成します。 –

+0

[カルーセル表示](https://blog.xamarin.com/flipthrough-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

関連する問題