亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Listview 列中顯示數據,而不是行的 Xamarin.Forms 中顯示數據

在 Listview 列中顯示數據,而不是行的 Xamarin.Forms 中顯示數據

C#
慕萊塢森 2022-09-04 16:28:32
嗨,伙計們,我正在嘗試使用如下圖所示的列表視圖以列格式顯示數據。我如何在Xamarin.Forms或Xamarin.Android中實現這一目標。列顯示
查看完整描述

2 回答

?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

溶液:


我寫了一個簡單的代碼來實現你圖片中的布局。我使用 :xamlGrid


<ContentPage.Content>

        <Grid x:Name="controlGrid" RowSpacing="2" ColumnSpacing="2">

            <Grid.RowDefinitions>

                <RowDefinition Height="*" />

                <RowDefinition Height="*" />

            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="*" />

                <ColumnDefinition Width="*" />

                <ColumnDefinition Width="*" />

                <ColumnDefinition Width="*" />

            </Grid.ColumnDefinitions>


            <StackLayout Orientation="Vertical"  Grid.Row="0" Grid.Column="0" BackgroundColor="White">

                <StackLayout Orientation="Horizontal">

                    <Label Text="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="CenterAndExpand" HeightRequest="40" />

                    <Label Text="TEXT" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Blue" WidthRequest="50" HeightRequest="40"/>

                </StackLayout>

                <BoxView  BackgroundColor="Gray" VerticalOptions="FillAndExpand"/>

            </StackLayout>


            <StackLayout Orientation="Vertical"  Grid.Row="0" Grid.Column="1" BackgroundColor="White">

                <StackLayout Orientation="Horizontal">

                    <Label Text="2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="CenterAndExpand"  HeightRequest="40" />

                    <Label Text="TEXT" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Blue" WidthRequest="50" HeightRequest="40"/>

                </StackLayout>

                <BoxView   BackgroundColor="Orange" VerticalOptions="FillAndExpand" />

            </StackLayout>


            <StackLayout Orientation="Vertical"  Grid.Row="0" Grid.Column="2" BackgroundColor="White">

                <BoxView   BackgroundColor="Green"  />

                <BoxView   BackgroundColor="Pink" VerticalOptions="FillAndExpand"/>

            </StackLayout>


            <StackLayout Orientation="Vertical"  Grid.Row="0" Grid.Column="3" BackgroundColor="White">

                <BoxView   BackgroundColor="Green" />

                <BoxView   BackgroundColor="Yellow" VerticalOptions="FillAndExpand" />

            </StackLayout>



            <StackLayout Orientation="Vertical"  Grid.Row="1" Grid.Column="0" BackgroundColor="White">

                <StackLayout Orientation="Horizontal">

                    <Label Text="5" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="CenterAndExpand"  HeightRequest="40" />

                    <Label Text="TEXT" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Blue" WidthRequest="50" HeightRequest="40"/>

                </StackLayout>

                <BoxView  BackgroundColor="Gray" VerticalOptions="FillAndExpand"/>

            </StackLayout>


            <StackLayout Orientation="Vertical"  Grid.Row="1" Grid.Column="1"  BackgroundColor="White">

                <BoxView   BackgroundColor="Green" />

                <BoxView   BackgroundColor="Pink" VerticalOptions="FillAndExpand" />

            </StackLayout>


            <StackLayout Orientation="Vertical"  Grid.Row="1" Grid.Column="2" BackgroundColor="White" >

                <Label  Text="777" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Green" HeightRequest="40"/>

                <BoxView   BackgroundColor="Orange" VerticalOptions="FillAndExpand" />

            </StackLayout>


            <StackLayout Orientation="Vertical"  Grid.Row="1" Grid.Column="3" BackgroundColor="White">

                <StackLayout Orientation="Horizontal">

                    <Label Text="8" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="CenterAndExpand"  HeightRequest="40" />

                    <Label Text="TEXT" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Blue" WidthRequest="50" HeightRequest="40"/>

                </StackLayout>

                <BoxView   BackgroundColor="Gold" VerticalOptions="FillAndExpand" />

            </StackLayout>


        </Grid>

    </ContentPage.Content> 

我設置了 's,讓它看起來像之間有黑線。ContentPageBackgroundColor="Black"Grids


您可以通過我的代碼中的控件自定義自己的布局。changing


這是:Screen Shot

http://img1.sycdn.imooc.com//631461de0001572213350750.jpg

查看完整回答
反對 回復 2022-09-04
?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

我通過使用插件DLToolkit.Forms.Controls.FlowListView實現了布局

http://img1.sycdn.imooc.com//631461f6000165df12790789.jpg

Xaml


<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"


         BackgroundColor="Black"

         xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView" >




    <ContentPage.Content>

    <flv:FlowListView x:Name="FlowListViewH" FlowColumnCount="{Binding ColumnCount}" SeparatorVisibility="Default" HasUnevenRows="True"

        FlowItemTappedCommand="{Binding ItemTappedCommand}" FlowLastTappedItem="{Binding LastTappedItem}"

        FlowItemsSource="{Binding Items}" FlowColumnMinWidth="220" >


        <flv:FlowListView.FlowColumnTemplate>

            <DataTemplate>


                <StackLayout Margin="5" BackgroundColor="Red" >

                    <Grid x:Name="controlGrid">

                        <Grid.RowDefinitions>

                            <RowDefinition Height="25*" />

                            <RowDefinition Height="25*" />

                            <RowDefinition Height="25*" />

                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>

                            <ColumnDefinition Width="50*" />

                            <ColumnDefinition Width="50*" />

                        </Grid.ColumnDefinitions>

                        <Label HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" BackgroundColor="Red" TextColor="Black"

                            Text="{Binding TableNumber}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="Large"/>

                        <Label HorizontalOptions="Fill" VerticalOptions="Fill" 

                            XAlign="Center" YAlign="Center" Text="{Binding ItemName}"  Grid.Row="1" Grid.Column="0" TextColor="Black"/>

                        <Label HorizontalOptions="FillAndExpand" VerticalOptions="Fill" 

                            XAlign="Center" YAlign="Center" Text="{Binding OrderedQuantity}"  Grid.Row="1" Grid.Column="1" TextColor="Black"/>

                        <Label HorizontalOptions="FillAndExpand" VerticalOptions="Fill" 

                            XAlign="Center" YAlign="Center" Text="{Binding Status}"  Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" TextColor="Black" BackgroundColor="White"/>

                    </Grid>

                </StackLayout>

            </DataTemplate>

        </flv:FlowListView.FlowColumnTemplate>


    </flv:FlowListView>

</ContentPage.Content>

xaml.cs


public  Page ()

        {

            NavigationPage.SetHasNavigationBar(this, false); //remove nav bar

            InitializeComponent ();

            LoadOrders();//populates Observable collection

           FlowListViewH.FlowItemsSource = OrdersForKitchenPage;//sets source to Observable collection


        }


查看完整回答
反對 回復 2022-09-04
  • 2 回答
  • 0 關注
  • 93 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號