不是为相对布局自动生成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"
tools:context=".MainActivity">
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout
我该怎么办?
是的,如果你在ConstraintLayout上拉动组件,它会猜出你想要的并为你设置属性。对于RelativeLayout,您需要使属性视图可见并从那里进行编辑。您需要编辑以下参数:
android:layout_below="@id/name"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times"