Linear Layout background not showing at all

2.7k views Asked by At

I set linear layout background as usual by

android:background="@drawable/xxx"

but it not shown at all both on eclipse as well as on device.

My XML file is given below :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:weightSum="10" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="4"
        android:background="#50595f"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/title_head"
            android:padding="15dp"
            android:text="Setup Wizard"
            android:textColor="@drawable/wp_text_white"
            android:textSize="30dp"
            android:textStyle="bold"
            android:typeface="normal" />

        <ScrollView style="@style/wp_scroll" >

            <LinearLayout style="@style/wp_1stLinner" >

                <TextView
                    android:id="@+id/toMakeProcess"
                    style="@style/wp_TextView"
                    android:layout_marginTop="20dp"
                    android:text="@string/toMakeProcess" />

                <RelativeLayout style="@style/wp_2stRelative" >

                    <TextView
                        android:id="@+id/bullet1"
                        style="@style/wp_Bullets"
                        android:layout_marginTop="10dp"
                        android:text="@string/bullet_code" />

                    <TextView
                        android:id="@+id/textOption1"
                        style="@style/wp_TextView"
                        android:layout_marginLeft="5dp"
                        android:layout_marginTop="18dp"
                        android:layout_toRightOf="@+id/bullet1"
                        android:text="@string/option1" />

                    <TextView
                        android:id="@+id/bullet2"
                        style="@style/wp_Bullets"
                        android:layout_below="@+id/textOption1"
                        android:layout_marginTop="10dp"
                        android:text="@string/bullet_code" />

                    <TextView
                        android:id="@+id/textOption2"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/textOption1"
                        android:layout_marginLeft="5dp"
                        android:layout_marginTop="18dp"
                        android:layout_toRightOf="@+id/bullet2"
                        android:text="@string/option2" />

                    <!--
                         <TextView
                        android:id="@+id/bullet3"
                        style="@style/wp_Bullets"
                        android:layout_below="@+id/textOption2"
                        android:text="@string/bullet_code" />




                    -->


                    <!--
                         <TextView
                        android:id="@+id/textOption3"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/textOption2"
                        android:layout_toRightOf="@+id/bullet3"
                        android:text="@string/option3" />




                    -->

                    <ImageView
                        android:id="@+id/iv_seperator"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/textOption2"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="25dp"
                        android:src="@drawable/separator_924" />

                    <TextView
                        android:id="@+id/tv_setup_wizard_heading"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/iv_seperator"
                        android:layout_marginTop="25dp"
                        android:text="@string/string_setup_wizard_heading" />

                    <TextView
                        android:id="@+id/tv_setup_wizard_1"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/tv_setup_wizard_heading"
                        android:layout_marginTop="20dp"
                        android:text="1." />

                    <ImageView
                        android:id="@+id/iv_setup_wizard_bt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tv_setup_wizard_heading"
                        android:layout_marginTop="20dp"
                        android:layout_toRightOf="@+id/tv_setup_wizard_1"
                        android:src="@drawable/icon_bluetooth_active" />

                    <TextView
                        android:id="@+id/tv_setup_wizard_first"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/tv_setup_wizard_heading"
                        android:layout_marginTop="20dp"
                        android:layout_toRightOf="@+id/iv_setup_wizard_bt"
                        android:text="@string/string_setup_wizard_first" />

                    <TextView
                        android:id="@+id/tv_setup_wizard_2"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/tv_setup_wizard_first"
                        android:layout_marginTop="20dp"
                        android:text="2." />

                    <ImageView
                        android:id="@+id/iv_setup_wizard_wheel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tv_setup_wizard_first"
                        android:layout_marginTop="20dp"
                        android:layout_toRightOf="@+id/tv_setup_wizard_2"
                        android:src="@drawable/icon_wheel_active" />

                    <TextView
                        android:id="@+id/tv_setup_wizard_second"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/tv_setup_wizard_first"
                        android:layout_marginTop="20dp"
                        android:layout_toRightOf="@+id/iv_setup_wizard_wheel"
                        android:text="@string/string_setup_wizard_second" />

                    <!--
                         <TextView
                        android:id="@+id/tv_setup_wizard_3"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/tv_setup_wizard_second"
                        android:layout_marginTop="20dp"
                        android:text="3." />

                    <ImageView
                        android:id="@+id/iv_setup_wizard_padlock"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tv_setup_wizard_second"
                        android:layout_marginTop="20dp"
                        android:layout_toRightOf="@+id/tv_setup_wizard_3"
                        android:src="@drawable/icon_padlock_active" />

                    <TextView
                        android:id="@+id/tv_setup_wizard_third"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/tv_setup_wizard_second"
                        android:layout_marginTop="20dp"
                        android:layout_toRightOf="@+id/iv_setup_wizard_padlock"
                        android:text="@string/string_setup_wizard_third" />

                    -->

                    <Button
                        android:id="@+id/nextBtn"
                        style="@style/wp_Button"
                        android:layout_below="@+id/tv_setup_wizard_second"
                        android:layout_marginTop="20dp"
                        android:text="@string/string_begin" />

                    <TextView
                        android:id="@+id/bottam_text"
                        style="@style/wp_TextView"
                        android:layout_below="@+id/nextBtn"
                        android:layout_marginTop="20dp"
                        android:text="@string/bottam_text" />
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/Linear_SetupWizard_Plain"
        style="@style/wp_1stLinner"
        android:layout_width="0dp"
        android:layout_weight="6"
        android:background="@drawable/shadow_setup"
        android:visibility="visible" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/breadcrumbs_greyed" />

        <TextView
            android:id="@+id/TextView_SetupWizard_Plain"
            style="@style/wp_TextView"
            android:layout_marginLeft="50dp"
            android:text="@string/string_setup_wizard_plain"
            android:textColor="#cfd0d2"
            android:textSize="36dp" />
    </LinearLayout>
</LinearLayout>
3

There are 3 answers

2
ssantos On

Just guessing, but you may be overriding background attribute in @style/wp_1stLinner

Also, you're missining android:layout_height attribute. Try something like android:layout_height="wrap_content"

Anyway, when nothing else works for me, I try simplifying my xml; you could try leaving just one child (the one with @drawable/shadow_setup); if the background appears, then start adding the rest of the children step by step.

2
Umer Farooq On

Change

android:layout_width="0dp"

to

android:layout_width="wrap_content"

This should solve your problem

0
user3760100 On

Initially, I had a LinearLayout(with layout_width="match_parent", and layout_height="wrap_content") inside a ScrollView as the only two elements in the XML. I specified android:background="my_color" and it was not working.

So, I just included the entire LinearLayout inside another RelativeLayout, whose layout_width and layout_height were set to "match_parent".

It worked.