gpt4 book ai didi

android - 在 Xamarin.Android 中设置 RelativeLayout 的背景颜色

转载 作者:搜寻专家 更新时间:2023-11-01 07:57:46 25 4
gpt4 key购买 nike

我正在尝试在我的 Xamarin Android 应用程序中的 RelativeLayout 搜索表单区域添加背景色。基本上我有一个 EditText 和一个按钮,它们应该包含在屏幕顶部的彩色背景中。使用下面的代码,应用了背景颜色,但我的 EditText 和按钮消失了,而它们下面的内容向上移动并占据了它们的位置。这是我的代码:

<?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 还是有更好的方法来构建它?

最佳答案

尝试这样的事情:

<?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:background="#ffffff">
<View
android:background="#EAF4F9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/header"
android:layout_alignBottom="@+id/btnOne" />
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="15dp"
android:layout_alignParentTop="true"
android:text="Hello" />
<EditText
android:inputType="numberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_alignParentLeft="true"
android:id="@+id/search"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:hint="Search for..." />
<Button
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSearch"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@+id/search" />
<TextView
android:text="Use my current location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/search"
android:layout_marginTop="10dp"
android:id="@+id/txtCurrentLocation"
android:gravity="center" />
<Button
android:id="@+id/btnOne"
android:text="Button One"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignRight="@id/strut"
android:layout_alignParentLeft="true"
android:layout_below="@id/txtCurrentLocation"
android:gravity="center" />
</RelativeLayout>

只需在需要的地方用 pixlui 版本替换按钮和 TextView 。

关于android - 在 Xamarin.Android 中设置 RelativeLayout 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25493272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com