XML : "Layout or its parent is useless". How to avoid this?

I have 2 bordered textviews to center vertically and horizontally, side by side as it is shown in the following image:

enter image description here

On top of each of these 2 textviews, I have to add a 'T' textview on the bottom left and a unit on the bottom right ('uV/m'). To do this I end up with the following layout xml code:

  <LinearLayout      android:id="@+id/layout_small_rectancle"      android:layout_width="match_parent"      android:layout_height="@dimen/drv3lite_small_rectangle_height"      android:baselineAligned="false"      android:layout_centerVertical="true"      android:orientation="horizontal" >        <!-- Small rectangles. Defines the whole width -->      <RelativeLayout           android:layout_width="0dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:gravity="center"           android:orientation="vertical" >            <!-- Small rectangle (left) -->          <RelativeLayout               android:layout_width="@dimen/drv3lite_small_rectangle_width"              android:layout_height="match_parent"              android:orientation="vertical" >                <TextView                  android:id="@+id/lblValueLTE"                  android:layout_width="match_parent"                   android:layout_height="match_parent"                  android:gravity="center"                  android:textColor="@color/color_green"                  android:textSize="@dimen/drv3lite_small_rectangle_text_size"                  android:textStyle="bold"                  android:text="1317"                   android:enabled="true"                  android:background="@drawable/selector_drv3lite_round_corners_lte"/>                <!-- Tag indicator -->                        <TextView                  android:id="@+id/lblTagLTE"                  android:layout_width="wrap_content"                   android:layout_height="wrap_content"                  android:layout_alignParentBottom="true"                  android:gravity="start"                   android:layout_marginLeft="5sp"                   android:layout_marginStart="5sp"                      android:textColor="@color/color_green"                  android:textSize="18sp"                  android:textStyle="bold"                  android:text="T" />                <!-- Units -->                        <TextView                  android:id="@+id/lblUnitsLTE"                  android:layout_width="wrap_content"                   android:layout_height="wrap_content"                  android:layout_alignParentRight="true"                  android:layout_alignParentEnd="true"                  android:layout_alignParentBottom="true"                  android:gravity="end"                  android:layout_marginRight="5sp"                      android:layout_marginEnd="5sp"                    android:textColor="@color/color_green"                  android:textSize="18sp"                  android:textStyle="bold"                  android:text="&#181;V/m" />                                               </RelativeLayout>      </RelativeLayout>      <!-- Small rectangles. Defines the whole width -->      <RelativeLayout           android:layout_width="0dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:gravity="center" >            <!-- Small rectangle (right) -->                                  <RelativeLayout               android:layout_width="@dimen/drv3lite_small_rectangle_width"              android:layout_height="match_parent"              android:orientation="vertical" >                <TextView                  android:id="@+id/lblValueMid"                  android:layout_width="match_parent"                   android:layout_height="match_parent"                  android:gravity="center"                  android:textColor="@color/color_orange"                  android:textSize="@dimen/drv3lite_small_rectangle_text_size"                   android:textStyle="bold"                  android:text="145"                   android:enabled="true"                 android:background="@drawable/selector_drv3lite_round_corners_mid"/>                <!-- Tag indicator -->                        <TextView                  android:id="@+id/lblTagMid"                  android:layout_width="30sp"                   android:layout_height="wrap_content"                  android:layout_alignParentBottom="true"                  android:gravity="start"                   android:layout_marginLeft="5sp"                   android:layout_marginStart="5sp"                      android:textColor="@color/color_orange"                  android:textSize="18sp"                  android:textStyle="bold"                  android:text="T" />                <!-- Units -->                        <TextView                  android:id="@+id/lblUnitsMid"                  android:layout_width="wrap_content"                   android:layout_height="wrap_content"                  android:layout_alignParentRight="true"                  android:layout_alignParentEnd="true"                  android:layout_alignParentBottom="true"                  android:gravity="end"                  android:layout_marginRight="5sp"                      android:layout_marginEnd="5sp"                    android:textColor="@color/color_orange"                  android:textSize="18sp"                  android:textStyle="bold"                  android:text="&#181;V/m" />          </RelativeLayout>                     </RelativeLayout>                 </LinearLayout>    

So:

  • First level: layout_small_rectangle allows me to center vertically;
  • Second level: the 2 RelativeLayout with weight of 1 allows me to distribute evenly the 2 textviews with borders horizontally;
  • Third level: relative layout that allows me to align to the left/right the 'T' and 'UV/m' textviews inside the bordered textview;

My question: is it possible to avoid the IDE warning saying that 'a layout is useless', caused by the successive RelativeLayout of level 2 and 3?

No comments:

Post a Comment