<?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>
Edited
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200px" android:background="@layout/roundedshape">
<Ga开发者_运维问答llery 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>
When I put a background for the RelativeLayout
it covers the two LinerLayouts
.
How can I have the background color and the two LinearLayout
s visible on top? Or is my perception wrong?
There's nothing wrong with your layout. If you set the background of the RelativeLayout to #FFFFFFFF
(white) then that's exactly what happens. The background (including where the LinearLayouts are) turns to white. But the LinearLayouts are on top of the RelativeLayout - you still see the buttons and any text displayed from within the LinearLayouts. If you set the background of the LinearLayouts to different colours you'll see this reflected in the layout - they are effectively on top of the RelativeLayout.
you are not wrong because relative layout is the father class in this layout file so relative layour's background covers both child class background by default.
if you want custom background in linear layout so write in linear layout tag
android:background = "#000000"
or
android:background="@drawable/ic_launcher_background"
精彩评论