【发布时间】:2015-11-02 07:31:48
【问题描述】:
我正在为 Android 制作一个小应用程序,但我遇到了 XAML 问题。
这是 XML 布局代码:
<RelativeLayout 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="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".reverse_screen"
android:textAllCaps="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:text="Enter a message"
android:layout_weight="1"
android:layout_width="0dp"
android:id="@+id/hi_field"
android:layout_height="wrap_content"
/>
<Button
android:text="@string/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Reversed:"/>
</RelativeLayout>
这就是它的样子:
我希望 TextView 元素位于 LinearLayout 中的 EditText 元素下方,但 IDE 不允许我这样做,因为它们不在同一个布局中。
不过,我想保留 LinearLayout 以保持 EditText 的权重以使其水平拉伸。
那么如何让LinearLayout中EditText下RelativeLayout中的TextView呢? android:layout_below 不起作用,因为它们位于不同的布局中。
我该如何解决?
【问题讨论】:
标签: android android-layout layout textview