2011-05-13 22 views
0

我使用嵌套LinearLayouts用於放置EditTexts和按鈕在屏幕的像這樣的中心目的ANDROID背景:爲LinearLayouts

Log In Page

我想改變這個背景。所以我插入另一個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> 

+0

我指定的layout_height和layout_width ..:d >>的android:layout_width =「FILL_PARENT 「 >> android:layout_height =」fill_parent「 – CMA 2011-05-13 08:57:47

回答

1

我不知道你是如何得到這個,而無需在主父線性指定任何layout_heightlayout_width

使用

android:layout_width="fill_parent" 
android:layout_height="fill_parent" 

layout.I認爲這將解決您的問題。

+0

xD我完全忘了把.. ..無論如何謝謝! :D – CMA 2011-05-13 08:54:54

+0

它解決了你的問題嗎? – 2011-05-13 09:07:33

+0

哦,是的!它確實解決了我的擔憂..謝謝無論如何..我已經投票答覆作爲我接受的答案..:D – CMA 2011-05-13 09:21:35

0

你能看到佈局,那是意想不到的?您沒有指定父級佈局的高度或寬度,所以我認爲這是問題。
在具有這些類型的情況下設計的,最好使用相對佈局提供主要特點垂詢佈局爲我們的心願

相關問題