Android Studio中的预览与emulator上运行的应用程序不同

Android Studio中的预览与emulator上运行的应用程序不同,android,xml,android-layout,layout,android-studio,Android,Xml,Android Layout,Layout,Android Studio,我是Android编程新手,我已经面临一个人们可以想象的最简单的问题:在屏幕上放置一个按钮。在activity.xml文件的预览中,一切正常,但在emulator中,一切都一团糟,按钮和标签不在它们应该在的位置 这里有一个例子:我把一个按钮放在浮动操作按钮的左边,但在模拟器中它就在上面 Android Studio预览: 仿真器: 以下是XML代码: activity.xml <?xml version="1.0" encoding="utf-8"?> <andr

我是Android编程新手,我已经面临一个人们可以想象的最简单的问题:在屏幕上放置一个按钮。在activity.xml文件的预览中,一切正常,但在emulator中,一切都一团糟,按钮和标签不在它们应该在的位置

这里有一个例子:我把一个按钮放在浮动操作按钮的左边,但在模拟器中它就在上面

Android Studio预览:

仿真器:

以下是XML代码:

activity.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true"
    tools:context="com.example.ed.wtf.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>



content.xml

        <?xml version="1.0" encoding="utf-8"?>
    <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"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.ed.wtf.MainActivity"
        tools:showIn="@layout/activity_main">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button"
            android:layout_marginBottom="65dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>
activity.xml
content.xml

我不知道为什么会出现这种差异,但当您为布局指定宽度和高度时,它将在emulator和studio预览中显示相同的内容

 <include layout="@layout/content_main" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

为预览和模拟器选择相同的分辨率、英寸和像素
从预览窗口的设备编辑器中

将floatingActionButton放入content main,并将alignParentBottom添加到其中,同时确保在预览布局中,将主题设置为与manifest.xml中相同的主题欢迎使用堆栈溢出!请花些时间为未来的读者详细说明你的答案。也许可以添加用户设置分辨率应采取的步骤?包括截图将帮助更多!