【问题标题】:The layout design isn't showing correctly in VS 2019布局设计在 VS 2019 中未正确显示
【发布时间】:2019-10-19 19:24:36
【问题描述】:

(image of the design surface) 我是 android 新手,我正在学习 (https://docs.microsoft.com/en-us/xamarin/android/get-started/hello-android/hello-android-quickstart?pivots=windows) 中的教程。问题是当我将元素从工具箱拖到设计表面时,它们都出现在 Visual Studio 中,但是当我调试程序并在手机上运行它时,它看起来很好,与教程完全一样。 我有 Visual Studio 2019,我刚刚从 Sdk 管理器下载了我需要的所有内容,这是我的 xml 代码:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:text="Enter a password:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="25px"
        android:minHeight="25px"
        android:id="@+id/textView1" />
    <EditText
        android:layout_width="246.5dp"
        android:layout_height="59.0dp"
        android:layout_below="@id/textView1"
        android:id="@+id/PhoneNumberText"
        android:text="1-855-XAMARIN"
        android:layout_marginTop="29.0dp"
        android:layout_marginBottom="0.0dp" />
    <Button
        android:text="Translate"
        android:layout_width="141.5dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/PhoneNumberText"
        android:id="@+id/TranslateButton"/>
    <TextView
        android:text="Text"
        android:layout_width="171.0dp"
        android:layout_height="33.5dp"
        android:layout_below="@id/TranslateButton"
        android:id="@+id/TranslatedPhoneWord"/>
</RelativeLayout>

【问题讨论】:

    标签: c# android visual-studio android-layout xamarin


    【解决方案1】:

    我添加了你所有的代码,在我这边运行良好。我第一次跟你一样。在我创建一个新布局以自己输入而不是复制后,它运行良好。

    它不会影响你的结果,也许 VS 那时不能很好地接受你的代码。不管怎样,没关系。

    如果您仍然想在预览中正确显示它,您可以尝试使用 LinearLayout,LinearLayout 会以线性方向显示子 View 元素,无论是垂直还是水平。 线性布局:https://docs.microsoft.com/en-us/xamarin/android/user-interface/layouts/linear-layout

    更改:RelativeLayout

    收件人:LinearLayout

    这种方式不需要使用layout_below。

    【讨论】:

    • 谢谢,更改为线性布局实际上使我能够将元素放置在彼此下方,并且预览也可以正常工作。文档中也提到了这一点,但我忽略了它,因为它说“Visual Studio 的较新版本包含稍微不同的应用程序模板。布局位于 content_main.axml 中,而不是 activity_main.axml。”即使我确实有最新版本,但我的项目中没有 content_main.axml,所以我忽略了第二个提示:“你应该将 标签更改为 ”。
    猜你喜欢
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多