简体   繁体   English

为什么 android studio 设计器不适用于相对布局

[英]Why android studio designer is not working for relative layout

安卓工作室设计师

is not auto generating XML codes for relative layout, it only works for constraint layout.不是为相对布局自动生成 XML 代码,它只适用于约束布局。

When I try to position a view inside a relative layout it only gets positioned at the top corner of the screen.当我尝试在相对布局内定位视图时,它只会定位在屏幕的顶角。

<?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"
    tools:context=".MainActivity">
    <Button
        android:id="@+id/button7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</RelativeLayout

What should I do?我该怎么办?

I faced the same issue and the i tried the following step;我遇到了同样的问题,我尝试了以下步骤;

  • Click on the magnet icon (next to the eye icon, top left, next to the Palette menu) so that it's not crossed out: this turns on Autoconnect.单击磁铁图标(在眼睛图标旁边,左上角,调色板菜单旁边),这样它就不会被划掉:这会打开自动连接。
  • this will now help you to move the button where ever you want to place it.这将帮助您将按钮移动到您想要放置的位置。

Try it and let me know.试试吧,让我知道。

Yes if you pull the component on ConstraintLayout, it will guess what you want and set the attributes for you.是的,如果您在 ConstraintLayout 上拉动组件,它会猜测您想要什么并为您设置属性。 For RelativeLayout, you need to make the attribute view visible and edit from there.对于RelativeLayout,您需要使属性视图可见并从那里进行编辑。 You need to edit parameters like these:您需要编辑如下参数:

 android:layout_below="@id/name"
 android:layout_alignParentLeft="true"
 android:layout_toLeftOf="@+id/times"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM