首页 > 解决方案 > 无法在 Xamarin.Forms 中使用 LinearLayout

问题描述

我正在学习 Xamarin.Forms 并遵循 Android 线性布局的以下文档 - https://developer.android.com/reference/android/widget/LinearLayout

我收到了这个错误

错误 XLS0414 找不到类型“LinearLayout”。确认您没有丢失程序集引用并且所有引用的程序集都已构建。DPM MainPage.xaml

同样在“输出”窗口中,消息说

在 xmlns http://xamarin.com/schemas/2014/forms中找不到类型 LinearLayout

这是视图

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DPM"
             x:Class="DPM.MainPage">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingLeft="16dp"
   android:paddingRight="16dp"
   android:orientation="horizontal"
   android:gravity="center">
        <!-- Place new controls here -->
        <Label Text="Prueba" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
        <Label Text="Bottom" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
    </LinearLayout>
</ContentPage>

如果需要更多信息来解决这个问题,请使用评论告诉我

标签: androidxamarinxamarin.forms

解决方案


Xamarin.Forms 中没有 LinearLayout,您可能会与 Xamarin Native 混淆。

有一个可以在 Xamarin.Forms 中实现的布局列表。

此外,您可能正在为这种结构寻找 StackLayout

Xamarin.Forms 布局


推荐阅读