基础知识Android UI设计问题

时间:2011-03-28 10:29:21

标签: android layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="200px"
    android:background="@layout/roundedshape"
    android:id="@+id/mainLayout"> 

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="100px" />

    <LinearLayout android:gravity="top"
        android:id="@+id/gallerytext"
        android:layout_width="match_parent"
        android:layout_height="50px"
        android:layout_below="@+id/gallery"
        android:layout_centerHorizontal="true">
        <TextView android:text="TextView"
            android:id="@+id/taskname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></TextView>
    </LinearLayout>
    <LinearLayout android:gravity="top"
        android:layout_width="match_parent"
        android:layout_height="50px"
        android:layout_below="@+id/gallerytext"
        android:layout_centerHorizontal="true" >
        <Button android:id="@+id/button_left"
            android:layout_width="27px"
            android:layout_height="27px"></Button>
        <Button android:text="Add"
            android:id="@+id/button_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></Button>
        <Button android:text="Edit"
            android:id="@+id/button_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></Button>
        <Button android:id="@+id/button_right"
            android:layout_width="27px"
            android:layout_height="27px"></Button>
    </LinearLayout>
</RelativeLayout>

被修改

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="200px" android:background="@layout/roundedshape"> 

<Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="100px"
/>

<TextView android:layout_below="@+id/gallery" android:text="TextView" android:id="@+id/taskname" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>

<Button android:id="@+id/button_left" android:layout_below="@+id/taskname" android:layout_width="27px" android:layout_height="27px" ></Button>
<Button android:text="Add" android:id="@+id/button_add" android:layout_below="@+id/taskname" android:layout_toRightOf="@+id/button_left" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Edit" android:id="@+id/button_edit" android:layout_below="@+id/taskname" android:layout_toRightOf="@+id/button_add" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:id="@+id/button_right" android:layout_below="@+id/taskname" android:layout_toRightOf="@+id/button_edit" android:layout_width="27px" android:layout_height="27px"></Button>

当我为RelativeLayout添加背景时,它涵盖了两个LinerLayouts

如何在背面显示背景颜色和两个LinearLayout?或者我的看法是错的?

2 个答案:

答案 0 :(得分:1)

您的布局没有任何问题。如果您将 RelativeLayout 的背景设置为#FFFFFFFF(白色),则确切地说会发生这种情况。背景(包括 LinearLayouts 所在的位置)变为白色。但 LinearLayouts 位于 RelativeLayout 之上 - 您仍会看到 LinearLayouts 中显示的按钮和任何文字。如果您将 LinearLayouts 的背景设置为不同颜色,您会在布局中看到这一点 - 它们实际上位于 RelativeLayout 之上。

答案 1 :(得分:0)

你没看错 因为相对布局是此布局文件中的父类,所以默认情况下相对layour的背景会覆盖两个子类的背景。

如果要在线性布局中自定义背景,请在线性布局标签中编写

android:background = "#000000"

android:background="@drawable/ic_launcher_background"