我已经更新了 Android Studio 2.3,之后我将默认 ConstrainLayout
作为模板 xml。
但是我有 RelativeLayout
作为子布局,我得到了以下警告。
此视图不受约束,它只有设计时位置,因此除非您添加约束,否则它将跳转到 (0,0)。
布局编辑器允许您将小部件放置在画布上的任何位置,并使用设计时属性(例如 layout_editor_absoluteX)记录当前位置。这些属性不会在运行时应用,因此如果您将布局推送到设备上,小部件可能出现在与编辑器中显示的位置不同的位置。要解决此问题,请通过从边缘连接拖动来确保小部件具有水平和垂直约束。
<?xml version="1.0" encoding="utf-8"?>
<layout 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.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.pratikbutani.demoapp.MainActivity"
tools:showIn="@layout/activity_main">
<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:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/activity_main"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
</layout>
在 RelativeLayout
上收到警告,我该怎么办?
原文由 Pratik Butani 发布,翻译遵循 CC BY-SA 4.0 许可协议
转到 Design,右键单击 relative layout 并选择 Constraint layout–>Infer Constraints