开发者

Basics Android UI design issue

开发者 https://www.devze.com 2023-02-20 01:01 出处:网络
<?xml version=\"1.0\" encoding=\"utf-8\"?> <RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
<?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 LinearLayouts 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"
0

精彩评论

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

关注公众号