Я пытаюсь добавить цвет фона в область формы поиска RelativeLayout в моем приложении Android в Xamarin. В основном у меня есть EditText и кнопка, которая должна содержаться в цветном фоне в верхней части экрана. Используя приведенный ниже код, применяется фоновый цвет, но мой EditText и кнопка исчезают, а содержимое под ними перемещается вверх и занимает свое место. Вот мой код:Настройка цвета фона RelativeLayout в Xamarin.Android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:screenOrientation="portrait"
android:background="#ffffff">
<RelativeLayout
android:id="@+id/TestLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EAF4F9">
<com.neopixl.pixlui.components.textview.TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Heading"
pixlui:typeface="Lato-Bold.ttf"
android:layout_marginBottom="15dp"/>
<EditText
android:inputType="numberDecimal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:id="@+id/SearchField"
android:layout_marginRight="10dp"/>
<Button
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:layout_toRightOf="@id/SearchField"
android:id="@+id/btnSearch"
android:layout_alignParentRight="true" />
<TextView
android:text="Use my current location"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="@id/SearchField"
android:id="@+id/txtCurrentLocation"
android:gravity="center"/>
</RelativeLayout>
<View
android:id="@+id/strut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<com.neopixl.pixlui.components.button.Button
android:id="@+id/btnOne"
android:text="Button One"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_alignRight="@id/strut"
android:layout_alignParentLeft="true"
android:layout_below="@id/txtCurrentLocation"
pixlui:typeface="Lato-Light.ttf"
android:gravity="center" />
<com.neopixl.pixlui.components.button.Button
android:text="Button Two"
android:id="@+id/btnTwo"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_alignLeft="@id/strut"
android:layout_alignParentRight="true"
android:layout_below="@id/txtCurrentLocation"
android:gravity="center"
pixlui:typeface="Lato-Light.ttf" />
</RelativeLayout>
Должен ли я быть с использованием LinearLayout здесь вместо или есть лучший способ построить это?
Почему оба элемента во вложенном 'RelativeLayout' используются' android: layout_below = "@ + id/textView1" '? Оставьте весь макет, пожалуйста. С 'RelativeLayout' вложенность почти всегда не нужна полностью, что так круто! – Cheesebaron
Я отредактировал приведенный выше код, чтобы показать полный макет. В основном у вас есть заголовок вверху с полем поиска под ним слева и кнопкой поиска справа от него. Ниже поля поиска и кнопки используется кнопка для текущего местоположения. Все это должно быть на светло-голубом фоне, который охватывает ширину родителя. Как еще я могу добиться этого, если его не нужно обертывать в какой-то контейнер? Благодаря! – cheriana