![](/img/trans.png)
[英]How to set in android background color to several linearlayouts at time in for() loop?
[英]ANDROID Background for LinearLayouts
我使用嵌套的LinearLayouts的目的是將EditTexts和Buttons放置在屏幕中央,如下所示:
我想更改此背景。 因此,我在其他所有內容的頂部插入了另一個LinearLayout。 但是它不起作用。 我所看到的只是黑色,表示我已經覆蓋了Editext和Buttons。
我認為必須正確安排布局。
關於如何放置背景的任何建議(即截至目前的顏色)?
我正在發布我的xml。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@+id/OceanBlue">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<EditText
android:id="@+id/et_username"
android:layout_width="170px"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_password"
android:password="true"
android:layout_width="170px"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button_ok"
android:text="Login"
android:layout_width="86px"
android:layout_height="wrap_content">
</Button>
<Button
android:id="@+id/button_cancel"
android:text="Cancel">
</Button>
</LinearLayout>
</LinearLayout>
我不知道如何在不指定任何layout_height
或layout_width
情況下獲得此信息
采用
android:layout_width="fill_parent"
android:layout_height="fill_parent"
在您的主要父級線性布局中。我認為它將解決您的問題。
您是否能夠看到布局,那是出乎意料的? 您沒有為父級布局指定高度或寬度,所以我認為這是問題所在。
在進行此類設計時,最好使用相對布局,它提供了主要功能來設計布局,這是我們希望的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.