Search code examples
androidandroid-layoutremoteview

LinearLayout Not Showing


I believe my problem stems from my use of weights and the RelativeLayout that immediately follows the LinearLayout not containing any...I can't get it to work though.

Here is what I am trying to accomplish (focusing on the center area with the background image) I get this by making background of LinearLayout the image...I can't do this with RemoteViews): enter image description here

Here is what I get with the xml that follows: enter image description here

<LinearLayout 
            android:id="@+id/forecast_ll"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:background="@drawable/transparent"
            android:layout_weight="4.5"
            android:weightSum="2">
            <RelativeLayout 
                android:id="@+id/widget_bg_rl"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <ImageView
                android:id="@+id/widget_bg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />
            <LinearLayout 
                android:id="@+id/current_ll"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:orientation="vertical"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:layout_weight="1">
                <TextView
                    android:id="@+id/update_time_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/at"
                    android:textSize="16dp"
                    android:textColor="@color/white"
                    />
                <TextView
                    android:id="@+id/current_temp_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-2dp"
                    android:text="35 F"
                    android:textSize="44dp"
                    android:textColor="@color/white"
                    android:includeFontPadding="false"
                    />
                <TextView
                    android:id="@+id/current_short_text_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-6dp"
                    android:text="partly cloudy"
                    android:textSize="16dp"
                    android:textColor="@color/white"
                    />
            </LinearLayout>
            <LinearLayout
                android:id="@+id/layout_divider"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_gravity="center_vertical"
                android:background="@color/white"
                />
            <LinearLayout 
                android:id="@+id/extended_forecast_ll"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_weight="1"
                android:weightSum="2">
                <LinearLayout 
                    android:id="@+id/day_one_ll"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:orientation="horizontal"
                    android:layout_weight="1">
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:padding="8dp">
                        <ImageView
                            android:id="@+id/day_one_image"
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@drawable/widget_icon"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="8dip"
                            />
                    </LinearLayout>
                   <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_gravity="center_vertical">
                        <TextView
                            android:id="@+id/day_one_daytv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="WED"
                            android:textColor="@drawable/white"
                            />
                        <TextView
                            android:id="@+id/day_one_hilo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="155 / 125"
                            android:textColor="@drawable/white"
                            />
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/layout_divider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/white"
                    />
                <LinearLayout 
                    android:id="@+id/day_two_ll"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:orientation="horizontal"
                    android:layout_weight="1">
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:padding="8dp">
                        <ImageView
                            android:id="@+id/day_two_image"
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@drawable/widget_icon"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="8dip"
                            />
                    </LinearLayout>
                   <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_gravity="center_vertical">
                        <TextView
                            android:id="@+id/day_two_daytv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="WED"
                            android:textColor="@drawable/white"
                            />
                        <TextView
                            android:id="@+id/day_two_hilo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="55 / 25"
                            android:textColor="@drawable/white"
                            />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            </RelativeLayout>
        </LinearLayout>

Solution

  • Here is my adjusted xml layout...removed weightsum and related items from outer most LinearLayout:

        <LinearLayout 
            android:id="@+id/forecast_ll"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:background="@drawable/transparent"
            android:layout_weight="4.5"
            >
            <RelativeLayout 
                android:id="@+id/widget_bg_rl"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <ImageView
                android:id="@+id/widget_bg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/al_widgetbg_01_05"
                android:scaleType="centerCrop" />
            <LinearLayout 
                android:id="@+id/current_ll"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:orientation="vertical"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                >
                <TextView
                    android:id="@+id/update_time_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/at"
                    android:textSize="16dp"
                    android:textColor="@color/white"
                    />
                <TextView
                    android:id="@+id/current_temp_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-2dp"
                    android:text="35 F"
                    android:textSize="44dp"
                    android:textColor="@color/white"
                    android:includeFontPadding="false"
                    />
                <TextView
                    android:id="@+id/current_short_text_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="-6dp"
                    android:text="partly cloudy"
                    android:textSize="16dp"
                    android:textColor="@color/white"
                    />
            </LinearLayout>
            <LinearLayout
                android:id="@+id/layout_divider"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:background="@color/white"
                android:layout_centerHorizontal="true"
                />
            <LinearLayout 
                android:id="@+id/extended_forecast_ll"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_toRightOf="@id/layout_divider"
                android:weightSum="2">
                <LinearLayout 
                    android:id="@+id/day_one_ll"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:orientation="horizontal"
                    android:layout_weight="1">
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:padding="8dp">
                        <ImageView
                            android:id="@+id/day_one_image"
                            android:layout_width="48dp"
                            android:layout_height="48dp"
                            android:src="@drawable/widget_icon"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="8dip"
                            />
                    </LinearLayout>
                   <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_gravity="center_vertical">
                        <TextView
                            android:id="@+id/day_one_daytv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="WED"
                            android:textColor="@drawable/white"
                            />
                        <TextView
                            android:id="@+id/day_one_hilo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="155 / 125"
                            android:textColor="@drawable/white"
                            />
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/layout_divider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginLeft="10dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/white"
                    />
                <LinearLayout 
                    android:id="@+id/day_two_ll"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:orientation="horizontal"
                    android:layout_weight="1">
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:padding="8dp">
                        <ImageView
                            android:id="@+id/day_two_image"
                            android:layout_width="48dp"
                            android:layout_height="48dp"
                            android:layout_gravity="center_vertical"
                            android:layout_marginLeft="8dip"
                            />
                    </LinearLayout>
                   <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_gravity="center_vertical">
                        <TextView
                            android:id="@+id/day_two_daytv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="WED"
                            android:textColor="@drawable/white"
                            />
                        <TextView
                            android:id="@+id/day_two_hilo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="55 / 25"
                            android:textColor="@drawable/white"
                            />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            </RelativeLayout>
        </LinearLayout>