开发者

ANDROID Background for LinearLayouts

i used nested LinearLayouts for the purpose of putting the EditTexts and Buttons in the center of the screen like this:

ANDROID Background for LinearLayouts

I want to change the background of this. So I inserted another LinearLayout on the top of everything else. But its not working. All I can see is black which indicates that I have covered the Editext and Buttons.

I think have to arrange the layouts properly.

any suggestions on how i may put a background(i.e. color, as of now)?

I am posting my 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>


I dont know how you are getting this without specifying any layout_height or layout_width

Use

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

in your main parent linear layout.I think it will solve your issue.


Are you able to see the layout, thats unexpected? You did not specify the height or width for parent layout so i think that is the problem.
In case of having these kinds of designs its better to use relative layout which provides main features to deign the layout as our wish

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜