在默认情况下,网格行中的条目看起来非常不自然。

huangapple go评论79阅读模式
英文:

Entrys in Rows of Grid default look really unnatural

问题

在.NET MAUI应用程序中,我想要创建一个类似表格的用户界面,其中包含第二列中的标签和输入框。

我在iOS上看到截图,我想知道为什么输入框默认会显得这么高?这对我来说看起来真的很糟糕。

是否有比设置输入框的HeightRequest更好的方式来使其看起来好看?即使设置VerticalAlignment="Center"也没有任何效果。

通常情况下,我不喜欢使用绝对数值,比如设置HeightRequest,但在这里,我不知道如何改进以使其看起来更自然。

所以,实际上,标签"Value A:"应该与输入框中的"0"垂直居中。因此,输入框需要上移或下移。

解决这类问题的首选方式是什么?

英文:

In a .NET MAUI App, I wanted to have a Table like UI with Label and Entrys in the second column.

<Grid RowDefinitions="Auto, Auto, Auto, Auto" ColumnDefinitions="150, *, *" Padding="15, 2, 0, 15" ColumnSpacing="10">
                        
	...
						
	<Label Grid.Row="1" Grid.Column="0" Text="Value A:" Background="Red"/>
	<StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalOptions="Center">
		<Entry Text="0" Placeholder="0" HorizontalTextAlignment="Center" Keyboard="Numeric" TextChanged="Entry_TextChanged" Focused="Entry_Focused"/>
		<Label Text="g"/>
	</StackLayout>
	<Label Grid.Row="1" Grid.Column="2" Text="0 g" HorizontalOptions="Center" />

	<Label Grid.Row="2" Grid.Column="0" Text="Value B:" Background="Blue"/>
	<StackLayout Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalOptions="Center">
		<Entry Text="0" Placeholder="0" HorizontalTextAlignment="Center" Keyboard="Numeric" TextChanged="Entry_TextChanged" Focused="Entry_Focused"/>
		<Label Text="g"/>
	</StackLayout>
	<Label Grid.Row="2" Grid.Column="2" Text="0 g" HorizontalOptions="Center" />
	
	...
</Grid>

在默认情况下,网格行中的条目看起来非常不自然。

I am asking myself why the Entrys get so high by default? The screenshot is from iOS. This really looks terrible to me.

Is there a better way to bring that in a good looking form than setting a HeightRequest for the Entrys? A VerticalAlignment="Center" even also does not have any effect.

Normally, I don't like to set something with absolute numbers like when setting a HeightRequest, but here, I don't know how this could be improved so that it looks naturally.

So, actually the Label "Value A:" should be vertically centered with the "0" of the Entry. Therefore the Entry needs to be move up or down.

What is the preferred way to solve such things?

答案1

得分: 0

在默认的网格行中,条目看起来非常不自然。

我为第三行的几个添加了VerticalOptions="Center"

<Grid RowDefinitions="Auto, Auto, Auto" ColumnDefinitions="150, *, *" Padding="15, 2, 0, 15" ColumnSpacing="20">
    
    <Label Grid.Row="1" Grid.Column="0" Text="Value A:" BackgroundColor="PaleVioletRed"/>
    <StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalOptions="Center">
        <Entry Text="0" Placeholder="0" HorizontalTextAlignment="Center" Keyboard="Numeric" />
        <Label Text="g"/>
    </StackLayout>
    <Label Grid.Row="1" Grid.Column="2" Text="0 g" HorizontalOptions="Center" />
    
    
    <Label Grid.Row="2" Grid.Column="0" Text="Value B:" BackgroundColor="CornflowerBlue"  VerticalOptions="Center"/>
    <StackLayout Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalOptions="Center" >
        <Entry Text="0" Placeholder="0" HorizontalTextAlignment="Center"  Keyboard="Numeric" />
        <Label Text="g" VerticalOptions="Center"/>
    </StackLayout>
    <Label Grid.Row="2" Grid.Column="2" Text="0 g" HorizontalOptions="Center" VerticalOptions="Center" />
    
</Grid>

效果如下:

在默认情况下,网格行中的条目看起来非常不自然。

在默认情况下,网格行中的条目看起来非常不自然。

希望能对您有所帮助。

英文:

> Entrys in Rows of Grid default look really unnatural

I add VerticalOptions=&quot;Center&quot; to several for third row:

&lt;Grid RowDefinitions=&quot;Auto, Auto, Auto&quot; ColumnDefinitions=&quot;150, *, *&quot; Padding=&quot;15, 2, 0, 15&quot; ColumnSpacing=&quot;20&quot; &gt;
    
    &lt;Label Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; Text=&quot;Value A:&quot; BackgroundColor=&quot;PaleVioletRed&quot;/&gt;
    &lt;StackLayout Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Orientation=&quot;Horizontal&quot; HorizontalOptions=&quot;Center&quot;&gt;
        &lt;Entry Text=&quot;0&quot; Placeholder=&quot;0&quot; HorizontalTextAlignment=&quot;Center&quot; Keyboard=&quot;Numeric&quot; /&gt;
        &lt;Label Text=&quot;g&quot;/&gt;
    &lt;/StackLayout&gt;
    &lt;Label Grid.Row=&quot;1&quot; Grid.Column=&quot;2&quot; Text=&quot;0 g&quot; HorizontalOptions=&quot;Center&quot; /&gt;
    
    
    &lt;Label Grid.Row=&quot;2&quot; Grid.Column=&quot;0&quot; Text=&quot;Value B:&quot; BackgroundColor=&quot;CornflowerBlue&quot;  VerticalOptions=&quot;Center&quot;/&gt;
    &lt;StackLayout Grid.Row=&quot;2&quot; Grid.Column=&quot;1&quot; Orientation=&quot;Horizontal&quot; HorizontalOptions=&quot;Center&quot; &gt;
        &lt;Entry Text=&quot;0&quot; Placeholder=&quot;0&quot; HorizontalTextAlignment=&quot;Center&quot;  Keyboard=&quot;Numeric&quot; /&gt;
        &lt;Label Text=&quot;g&quot; VerticalOptions=&quot;Center&quot;/&gt;
    &lt;/StackLayout&gt;
    &lt;Label Grid.Row=&quot;2&quot; Grid.Column=&quot;2&quot; Text=&quot;0 g&quot; HorizontalOptions=&quot;Center&quot; VerticalOptions=&quot;Center&quot; /&gt;
    
&lt;/Grid&gt;

Here is the effect:

在默认情况下,网格行中的条目看起来非常不自然。

在默认情况下,网格行中的条目看起来非常不自然。

Wish it can help you.

huangapple
  • 本文由 发表于 2023年7月11日 04:12:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657036.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定