2017-08-10 20 views
0

在下面Xamarin形式的代码,我试图对准入口图片为Bootstrap input group addon alignment problems与入口在Xamarin对齐图像格式

解释创造视觉外观像一个自举输入组,但它有以下缺点:

  1. 的图像需要更多的宽度和高度小于指定HeightRequest和WidthRequest
  2. 有图片和条目
之间的不必要的空间

如何解决这个问题?

enter image description here

XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:local="clr-namespace:MyHomeScreen2;assembly=MyHomeScreen2" 
      x:Class="MyHomeScreen2.InputFormTest" 
      NavigationPage.HasNavigationBar="False"> 
    <ContentPage.Content> 
     <Grid x:Name="inputGrid" Grid.Row="1" ColumnSpacing="0" RowSpacing="0" Padding="0" BackgroundColor="#606060"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 

      <Label x:Name="lblReading" TextColor="White" Text="READING" Grid.Row="0" Margin="15"></Label> 

      <StackLayout Grid.Row="1" Orientation="Horizontal"> 
       <Image Source="homea.png" Aspect="AspectFit" 
         HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" 
         HeightRequest="10" WidthRequest="20" 
         BackgroundColor="Silver" ></Image> 
       <Entry x:Name="myEntry" TextColor="Black" Text="1" Keyboard="Numeric" BackgroundColor="White" 
          Opacity="0.9" HeightRequest="20"> 
       </Entry> 
      </StackLayout> 
     </Grid> 
    </ContentPage.Content> 
</ContentPage> 
+0

你不能 “FillAndExpand” 的水平和垂直图像的选项。用“CenterAndExpand”覆盖它,并在Entry视图中放置“FillAndExpand”布局选项。 –

+0

我没试过。但我确定问题在那里。让我看看我能否实现它,我会告诉你。 (对不起英语不好) –

+0

1将水平和垂直选项更改为中心,开始或结束,以及2在Stacklayout上设置Spacing =“0” – Nick

回答

1

(对不起,我英文不好)

试试这个方法,它为我工作。

XAML:

<Grid Grid.Row="1" ColumnSpacing="0" 
     RowSpacing="0" 
     Padding="0" 
     BackgroundColor="#606060"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <Label Grid.Row="0" 
      x:Name="lblReading" 
      TextColor="White" 
      Text="READING" 
      Margin="15"/> 
    <StackLayout Grid.Row="1" 
       Orientation="Horizontal" 
       Spacing="1" 
       Margin="5,0"> 
     <Image Source="lan_connect_white_36dp" 
       Aspect="AspectFit" 
       HorizontalOptions="Center" 
       VerticalOptions="CenterAndExpand" 
       HeightRequest="40" 
       WidthRequest="40" 
       BackgroundColor="Silver"/> 
     <Entry x:Name="myEntry" 
       TextColor="Black" 
       Text="1" 
       Keyboard="Numeric" 
       BackgroundColor="White" 
       HorizontalOptions="FillAndExpand" 
       VerticalOptions="CenterAndExpand" 
       Opacity="0.9"> 
     </Entry> 
    </StackLayout> 
</Grid> 

结果:

Sample

+0

谢谢。但如何删除图像和条目之间的空间 – Lijo

+0

只需将'Spacing =“1”'更改为'Spacing =“0”' –