简体   繁体   English

LinearLayouts的ANDROID背景

[英]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: 我使用嵌套的LinearLayouts的目的是将EditTexts和Buttons放置在屏幕中央,如下所示:

登录页面

I want to change the background of this. 我想更改此背景。 So I inserted another LinearLayout on the top of everything else. 因此,我在其他所有内容的顶部插入了另一个LinearLayout。 But its not working. 但是它不起作用。 All I can see is black which indicates that I have covered the Editext and Buttons. 我所看到的只是黑色,表示我已经覆盖了Editext和Buttons。

I think have to arrange the layouts properly. 我认为必须正确安排布局。

any suggestions on how i may put a background(ie color, as of now)? 关于如何放置背景的任何建议(即截至目前的颜色)?

I am posting my xml. 我正在发布我的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 我不知道如何在不指定任何layout_heightlayout_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 在进行此类设计时,最好使用相对布局,它提供了主要功能来设计布局,这是我们希望的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM