我想在xamarin中设置html标签文本背景色的宽度,但是它覆盖的颜色和文本的长度一样长。如何覆盖整个背景?我希望红色的区域和后面的绿松石一样宽。
的数据
我从服务发送html代码,如下所示
Imd.DR = (d.OncelikID != (int)Sabitler.Oncelik.Yuksek) ? Fonksiyonlar.ModulDurumVer(d.DurumID ?? 0).Adi : "<span style=\"display:block; text-align:center; background-color:#ff0000; margin:auto; \">"
+ Fonksiyonlar.ModulDurumVer(d.DurumID ?? 0).Adi + "<span>";
字符串
这是我在xamarin中的xaml代码:
<htmlLabel:HtmlLabel Text="{Binding DR}" BackgroundColor="#b2e8e7" TextColor="Black" FontSize="10" HorizontalTextAlignment="Center" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" />
型
下面是完整的XAML代码:
<?xml version="1.0" encoding="utf-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="OzelKalem.Views.ListeContentViews.AramaListeContent"
xmlns:htmlLabel="clr-namespace:LabelHtml.Forms.Plugin.Abstractions;assembly=OzelKalem"
xmlns:Prl="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh"
xmlns:local="clr-namespace:OzelKalem.Models"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true"
BackgroundColor="#00b3ae"
NavigationPage.HasNavigationBar="false">
<ContentView.Content>
<Grid VerticalOptions="FillAndExpand" BackgroundColor="White" Margin="0" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Margin="10">
<StackLayout Orientation="Horizontal" >
<Button x:Name="Geri" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Clicked="TarihDegistir" CommandParameter="-1" ContentLayout="Top,5" BackgroundColor="#edebeb" BorderColor="#cccccc" BorderWidth="1"
ImageSource="{local:ResourceResimExt ResourceId=OzelKalem.Content.images.leftarrow.png }" WidthRequest="30" HeightRequest="30" />
<Label Text="" x:Name="lbl_GosterimTurID" IsVisible="False"></Label>
<Label Text="" x:Name="lbl_VarsayilanTarih" IsVisible="False"></Label>
<StackLayout Orientation="Vertical" VerticalOptions="Center">
<Label Text="Saat" HorizontalOptions="Center" x:Name="lbl_Tarih" VerticalOptions="Center" FontSize="10" HeightRequest="8" Margin="0" />
<Label Text="Saat" HorizontalOptions="Center" x:Name="lbl_GunTarih" VerticalOptions="Center" FontSize="10" HeightRequest="8" Margin="0"/>
</StackLayout>
<Button x:Name="ileri" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Clicked="TarihDegistir" CommandParameter="1" ContentLayout="Top,5" BackgroundColor="#edebeb" BorderColor="#cccccc" BorderWidth="1"
ImageSource="{local:ResourceResimExt ResourceId=OzelKalem.Content.images.rightarrow.png }" WidthRequest="30" HeightRequest="30" />
</StackLayout>
</Grid>
<Grid Grid.Row="2" RowSpacing="0" Margin="10,0,10,0" >
<Prl:PullToRefreshLayout IsPullToRefreshEnabled="True" BackgroundColor="White" RefreshBackgroundColor="White" x:Name="plr_Arama" VerticalOptions="FillAndExpand" >
<ScrollView>
<StackLayout x:Name="stc_Arama" BindableLayout.ItemsSource="{Binding Icerik}" BackgroundColor="White" IsTabStop="True" VerticalOptions="StartAndExpand">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout >
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="arama_Secim" />
</StackLayout.GestureRecognizers>
<Grid BackgroundColor="#0070c0" ColumnSpacing="1" RowSpacing="1" Padding="0,0,0,1" VerticalOptions="Start">
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{OnIdiom
Phone= {OnPlatform iOS=4*, Android=3*},
Tablet= {OnPlatform iOS=2*, Android=2*}}">
</ColumnDefinition>
<ColumnDefinition Width="{OnIdiom
Phone= {OnPlatform iOS=6*, Android=5*},
Tablet= {OnPlatform iOS=6*, Android=6*}}">
</ColumnDefinition>
<ColumnDefinition Width="{OnIdiom
Phone= {OnPlatform iOS=6*, Android=5*},
Tablet= {OnPlatform iOS=6*, Android=6*}}">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="{Binding ID}" IsVisible="False" x:Name="ID" FontSize="10" />
<ContentView Grid.Column="0">
<StackLayout >
<Label Text="{Binding GSaat}" HorizontalTextAlignment="Center" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="10" />
<ContentView BackgroundColor="#00b3ae" >
<ContentView BackgroundColor="White" Margin="0,1,0,0" Padding="1">
<htmlLabel:HtmlLabel Text="{Binding DR}" BackgroundColor="#b2e8e7" TextColor="Black" FontSize="10" HorizontalTextAlignment="Center" HorizontalOptions="Fill" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" />
</ContentView>
</ContentView>
<Image Source="{local:ResourceResimExt ResourceId=OzelKalem.Content.images.modultalimat.png }" x:Name="img_Logo" IsVisible="{Binding isTalimatSurecli,Converter={local:DegerKontrolkExtyeni}}" WidthRequest="15" HeightRequest="15"></Image>
</StackLayout>
</ContentView>
<StackLayout Grid.Column="1">
<!--<Label Text="{Binding KListe,Converter={local:KatilimciListeModel}}" HorizontalOptions="Center" LineBreakMode="CharacterWrap" FontSize="12" />-->
<htmlLabel:HtmlLabel Text="{Binding KListe,Converter={local:KatilimciListeExt}}" FontSize="10" />
<Label Text="{Binding SListe,Converter={local:SurecListeExt}}" FontAttributes="Bold" FontSize="8" />
</StackLayout>
<StackLayout Grid.Column="2" Orientation="Horizontal">
<htmlLabel:HtmlLabel Text="{Binding Ack}" Style="{DynamicResource ListItemTextStyle}" FontSize="10" HorizontalOptions="StartAndExpand" />
<!--<Label Text="{Binding Ack}" Style="{DynamicResource ListItemTextStyle}" FontSize="10" HorizontalOptions="StartAndExpand" />-->
<Label Text="{Binding YKA}" TextColor="Black" HorizontalOptions="End" VerticalOptions="Start" FontSize="10" FontAttributes="Bold" IsVisible="{Binding YKA,Converter={local:DegerKontrolkExt}}" MinimumWidthRequest="40" />
<!--<Label Text="{Binding YKA}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="12" /-->
</StackLayout>
</Grid>
</Grid>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>
</Prl:PullToRefreshLayout>
</Grid>
</Grid>
</ContentView.Content>
</ContentView>
型
2条答案
按热度按时间eyh26e7m1#
通过将HorizontalOptions设置为
Fill
,它将确保View填充其父布局的宽度。你可以试试下面的:
字符串
zengzsys2#
这是最后一种情况
的数据
我从服务发送HTML代码如下:
字符串
我的xmal代码:
型