【发布时间】:2018-01-29 03:57:58
【问题描述】:
我正在使用 Xamarin Forms 为 Abdroid 和 UWP 创建一个类似聊天的应用程序。我想创建一个类似于this 的页脚布局 (意味着 2 个按钮和一个水平方向的编辑器)。
我使用以下 xaml 在图像中创建了布局:
<Grid >
<Grid.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android">5,0,5,5</On>
<On Platform="Windows">5,0,5,25</On>
</OnPlatform>
</Grid.Margin>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Editor x:Name="MessageText" Text="" Grid.Column="0" />
<local:RoundedButton x:Name="Button2" Clicked="click2" BackgroundColor="#000000" Grid.Column="1" WidthRequest="50" HeightRequest="50" BorderRadius="25" VerticalOptions="Center" />
<local:RoundedButton x:Name="Button1" Clicked="click1" BackgroundColor="#000000" Grid.Column="2" WidthRequest="50" HeightRequest="50" BorderRadius="25" VerticalOptions="Center"/>
</Grid>
这种布局的问题是编辑器不能完全显示超过一行。当我继续编写比编辑器宽度更长的文本时,我会得到类似this 的信息。如您所见,第一行已被截断,当我开始新行时,仅显示其底部。
据我所知,使用 LinearLayout 和 layout_weight 属性在 Android 中创建这种布局非常容易。但我现在尽量避免为整个页脚创建渲染器。
编辑
这是我在 Android 中编写的一个示例,其中包含想要的结果:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:hint="Enter a message"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="hi"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="bi"/>
</LinearLayout>
结果如下:
【问题讨论】:
标签: android xamarin xamarin.android uwp xamarin.forms