Xamarin 知道如何在CarouseView自身中添加CarouseView指示器吗?
我正在使用旋转视图显示一些视图 它们中的每一个基本上是2个堆栈布局 像这样 到目前为止,我所做的是为这两个堆栈布局创建一个带模板的旋转视图Xamarin 知道如何在CarouseView自身中添加CarouseView指示器吗?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我正在使用旋转视图显示一些视图 它们中的每一个基本上是2个堆栈布局 像这样 到目前为止,我所做的是为这两个堆栈布局创建一个带模板的旋转视图 <CarouselView x:Name="MyCarouselView" IsVisible="{Binding ShouldShow}" ItemsSource="{Binding MyItemSource}"
<CarouselView
x:Name="MyCarouselView"
IsVisible="{Binding ShouldShow}"
ItemsSource="{Binding MyItemSource}"
Scrolled="CarouselView_Scrolled">
<CarouselView.ItemTemplate>
<DataTemplate>
<ContentView>
<FlexLayout Direction="Column" JustifyContent="SpaceBetween">
<StackLayout FlexLayout.Basis="25%">
<elements:TopView Data="{Binding}"/>
</StackLayout>
<StackLayout FlexLayout.Basis="75%">
<elements:BottomView Data="{Binding}"/>
</StackLayout>
</FlexLayout>
</ContentView>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
注意:视图绑定到不同的值,但为了简单起见,我在这里编写了一个更简单的数据模板。
它工作得很好,在装订或其他方面没有问题
我试图做的是添加指示器,向用户显示有更多的项目,以及他现在看到的项目。(小圆圈或类似的东西)
问题是我想在两个视图之间显示它们,就像这样
你知道怎么做吗?
任何其他实现想要的结果的方法都是受欢迎的
请接受并感谢您。您可以通过两种方法实现这一点:-
网格
,您可以将两个控件放置在同一个网格行
。
将VerticalOptions=“FillAndExpand”
分配给旋转木马视图,并将VerticalOptions=“Center”
分配给指示灯视图如果您有更多疑问,请告诉我。您可以通过两种方法实现此目的:-
网格
,您可以将两个控件放置在同一个网格行
。
将VerticalOptions=“FillAndExpand”
分配给旋转木马视图,并将VerticalOptions=“Center”
分配给指示灯视图如果您有更多疑问,请告诉我。实现这一点的简单方法是使用网格来实现:
<Grid>
<!-- Place new controls here -->
<CarouselView x:Name="CustomCarouselView"
IndicatorView="indicatorView"
VerticalOptions="FillAndExpand"
>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<ContentView BackgroundColor="LightBlue" >
<Label Text="{Binding TopViewTitle}" FontSize="Header" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HeightRequest="250"/>
</ContentView>
<ContentView BackgroundColor="LightGray" Margin="0,80,0,0">
<Label Text="{Binding BottomViewTitle}" FontSize="Header" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HeightRequest="250" />
</ContentView>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="indicatorView"
IndicatorsShape="Square"
IndicatorColor="LightGray"
SelectedIndicatorColor="DarkGray"
VerticalOptions="Center"
Margin="0,-150,0,0" />
</Grid>
效果如预期:
另一种方法您可以使用RelativeLayout来实现:
<RelativeLayout>
<!-- Place new controls here -->
<CarouselView x:Name="CustomCarouselView"
IndicatorView="indicatorView"
>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<ContentView BackgroundColor="LightBlue">
<Label Text="{Binding TopViewTitle}"
FontSize="Header"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
HeightRequest="250" />
</ContentView>
<ContentView BackgroundColor="LightGray"
Margin="0,80,0,0">
<Label Text="{Binding BottomViewTitle}"
FontSize="Header"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
HeightRequest="250" />
</ContentView>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="indicatorView"
IndicatorsShape="Square"
IndicatorColor="LightGray"
SelectedIndicatorColor="DarkGray"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.5,Constant=-25}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.5,Constant=-75}"
/>
</RelativeLayout>
在这里,您可以修改指示器视图的RelativeLayout.XConstraint
和RelativeLayout.YConstraint
,以设置两个ContentView
之间的间距。边际属性
底部ContentView的属性也需要设置,它的作用是显示两个ConentView之间的空间实现这一点的简单方法是使用网格:
<Grid>
<!-- Place new controls here -->
<CarouselView x:Name="CustomCarouselView"
IndicatorView="indicatorView"
VerticalOptions="FillAndExpand"
>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<ContentView BackgroundColor="LightBlue" >
<Label Text="{Binding TopViewTitle}" FontSize="Header" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HeightRequest="250"/>
</ContentView>
<ContentView BackgroundColor="LightGray" Margin="0,80,0,0">
<Label Text="{Binding BottomViewTitle}" FontSize="Header" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HeightRequest="250" />
</ContentView>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="indicatorView"
IndicatorsShape="Square"
IndicatorColor="LightGray"
SelectedIndicatorColor="DarkGray"
VerticalOptions="Center"
Margin="0,-150,0,0" />
</Grid>
效果如预期:
另一种方法您可以使用RelativeLayout来实现:
<RelativeLayout>
<!-- Place new controls here -->
<CarouselView x:Name="CustomCarouselView"
IndicatorView="indicatorView"
>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<ContentView BackgroundColor="LightBlue">
<Label Text="{Binding TopViewTitle}"
FontSize="Header"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
HeightRequest="250" />
</ContentView>
<ContentView BackgroundColor="LightGray"
Margin="0,80,0,0">
<Label Text="{Binding BottomViewTitle}"
FontSize="Header"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
HeightRequest="250" />
</ContentView>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="indicatorView"
IndicatorsShape="Square"
IndicatorColor="LightGray"
SelectedIndicatorColor="DarkGray"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.5,Constant=-25}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.5,Constant=-75}"
/>
</RelativeLayout>
在这里,您可以修改指示器视图的RelativeLayout.XConstraint
和RelativeLayout.YConstraint
,以设置两个ContentView
之间的间距。边际属性
底部内容视图也需要设置,它的效果是显示两个ConentView之间的空间。我唯一能想到的是指示视图顶部的CV层,并使CV有一个透明的背景。我唯一能想到的是指示视图顶部的CV层,并且让简历有一个透明的背景感谢你的详细回答它起了作用。在此之前,我不知道我们在Xamarin有一个相对的布局。下一步我将测试相对论,学习新东西不会有什么坏处。@LeoJebran很高兴这会有帮助!如果以后还有其他问题,欢迎在SO中提问:)感谢您提供了非常详细的答案。在此之前,我不知道我们在Xamarin有一个相对的布局。下一步我将测试相对论,学习新东西不会有什么坏处。@LeoJebran很高兴这会有帮助!如果以后还有其他问题,欢迎提问:)谢谢你的回答,我希望我能接受他们两个最欢迎!没有问题。谢谢谢谢你的回答,我希望我能接受他们两个最欢迎!没有问题。谢谢