【问题标题】:Items Don't Stay Where Placed With Drag Drop Feature in Android Studio项目不会停留在 Android Studio 中拖放功能的位置
【发布时间】:2017-03-24 06:11:20
【问题描述】:

因此 Android Studio 在设计选项卡中具有拖放功能。我能够将元素放置在我想要的位置,并且布局在屏幕上看起来很棒。

但是,当我运行应用模拟器时,它看起来完全不同。一切都被推到屏幕的左上角,离我在设计模式下放置的位置很远。

有没有办法让您的元素在模拟器中以与您在设计模式下放置它们的方式相同的方式显示?现在我每次都得回去编辑所有代码。

下面有我的代码,以及下面的图片链接,以进一步阐明我的观点。Comparison of Design mode vs App Emulator

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context="com.example.luke.currencyconverter.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter The Amount in Dollars"
        tools:layout_editor_absoluteX="-159dp"
        tools:layout_editor_absoluteY="126dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="403dp"
        android:layout_height="0dp"
        android:text="Enter The Amount in Dollars:"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        tools:layout_editor_absoluteX="33dp"
        tools:layout_editor_absoluteY="365dp" />

    <ImageView
        android:id="@+id/currency"
        android:layout_width="361dp"
        android:layout_height="450dp"
        app:srcCompat="@drawable/currency"
        tools:layout_editor_absoluteX="12dp"
        tools:layout_editor_absoluteY="-117dp" />

    <Button
        android:id="@+id/convert"
        android:layout_width="361dp"
        android:layout_height="wrap_content"
        android:onClick="convert"
        android:text="Convert"
        tools:layout_editor_absoluteX="12dp"
        tools:layout_editor_absoluteY="462dp" />

    <EditText
        android:id="@+id/dollarField"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberDecimal"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="408dp" />

</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 不推荐拖放。
  • 你应该发布你的代码。
  • 使用线性布局拖放仅受设置约束或不同设备的屏幕尺寸不同,可能无法按预期工作。

标签: android android-studio drag-and-drop emulation


【解决方案1】:

Android 的拖放只会将对象放置在屏幕内。要将其保留在那里,您应该修改 xml,以便对象相互约束。

您可以使用相对布局或约束布局,以便更轻松地设计布局。

【讨论】:

    【解决方案2】:

    我想通了。我使用的是“约束布局”,我需要使用“相对布局”。

    【讨论】:

      【解决方案3】:

      我也遇到了这个错误,听起来很烦人,我的解决方案是删除我的 xml 文件并重新创建它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-07
        • 2013-07-01
        • 1970-01-01
        • 2019-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多