Android 试图在ConstraintLayout内定位视图
我尝试在Android studio中定位我的三个图像按钮。但是,每次我使用design editor将imagebuttons定位到正确的位置时,它在我运行应用程序时不会生效。使用设计编辑器而不是文本编辑器,会显示以下消息: 此视图不受约束,它只有设计时位置,因此除非添加较少的约束,否则它将跳转到(0,0) 如果我只需要在xml编辑器中添加约束,那么如何在xml编辑器中添加约束 此外,这一行将添加到xml编辑器中:Android 试图在ConstraintLayout内定位视图,android,xml,android-layout,android-studio,Android,Xml,Android Layout,Android Studio,我尝试在Android studio中定位我的三个图像按钮。但是,每次我使用design editor将imagebuttons定位到正确的位置时,它在我运行应用程序时不会生效。使用设计编辑器而不是文本编辑器,会显示以下消息: 此视图不受约束,它只有设计时位置,因此除非添加较少的约束,否则它将跳转到(0,0) 如果我只需要在xml编辑器中添加约束,那么如何在xml编辑器中添加约束 此外,这一行将添加到xml编辑器中: tools:layout\u editor\u absoluteY=“80dp
tools:layout\u editor\u absoluteY=“80dp”
工具:布局编辑器
我正在使用ConstraintLayout而不是RelativeLayout。。。
My main.activity xml代码:
<ImageButton
android:id="@+id/positive_Button"
android:layout_width="150dp"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitCenter"
app:srcCompat="@drawable/positive"
android:gravity="left"
tools:layout_editor_absoluteY="80dp"
tools:layout_editor_absoluteX="39dp" />
<ImageButton
android:id="@+id/neutral_Button"
android:scaleType="fitCenter"
android:layout_width="150dp"
android:layout_height="150dp"
app:srcCompat="@drawable/neutral"
android:background="@null"
android:adjustViewBounds="true"
tools:layout_editor_absoluteY="80dp"
tools:layout_editor_absoluteX="230dp" />
<ImageButton
android:id="@+id/negative_Button"
android:layout_width="150dp"
android:layout_height="150dp"
app:srcCompat="@drawable/negative"
android:background="@null"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
tools:layout_editor_absoluteY="80dp"
tools:layout_editor_absoluteX="412dp" />
属性工具:仅用于开发目的。工具:在构建时剥离属性。您希望如何定位视图?然后我可以提出一个解决方案。你可以用
android:layout_marginLeft=“80dp”
例如,要在编辑器的“设计”选项卡中定位X。,右键单击您的小部件ConstraintLayout,然后单击下拉列表中的“推断约束”。IDE将自动为您的应用程序添加代码
Constraint Layout ---> Infer Constraint
在MainActivity.java
中,将Activity
更改为AppCompactActivity
布局文件中的父视图是什么???发布您的xml代码。请提供您的所有xml代码。ConstraintLayout
是父布局吗?@Jens尝试编辑您的问题标题以尝试将视图放置在内部ConstraintLayout
。这样其他面对问题的人才能找到解决办法。哈哈,ofc。。。有时候这太容易了