【发布时间】:2019-01-25 13:33:48
【问题描述】:
我正在尝试将一些按钮/文本视图或任何其他组件添加到我的相对布局中。除了左上角,我不能把它们放在任何地方。但是,如果我编辑 XML 代码,它可以正常工作。
Here is the screenshot of current status
我已经将布局更改为 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" -
可能首先你会读到一些关于RelativeLayout的东西?
标签: android android-layout android-relativelayout