我想在我的RelativeLayout中添加一些按钮/文本视图或其他组件。但是我只能把它们放在左上角,而无法放置在其他位置。然而,如果我编辑XML代码,则可以正常工作。
我已经将布局更改为RelativeLayout,但仍然没有成功。(Android Studio 3.3)
我的布局XML如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>
我希望将这些按钮/文本视图相对移动,但它们却只停留在左上角。
RelativeLayout
更改为LinearLayout
。否则,您必须使用选项,如android:layout_alignParentRight="true"
或在textview
中使用android:layout_alignRight="@id/button"
。 - Pierre