android - "Layout or its parent is useless". How to avoid this? -


i have 2 bordered textviews center vertically , horizontally, side side shown in following image:

enter image description here

on top of each of these 2 textviews, have add 't' textview on bottom left , unit on bottom right ('uv/m'). end 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 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 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 center vertically;
  • second level: 2 relativelayout weight of 1 allows me distribute evenly 2 textviews borders horizontally;
  • third level: relative layout allows me align left/right 't' , 'uv/m' textviews inside bordered textview;

my question: possible avoid ide warning saying 'a layout useless', caused successive relativelayout of level 2 , 3?

you can remove 2 parent relativelayouts , apply weights children same effect.

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/layout_small_rectancle"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_centervertical="true"     android:baselinealigned="false"     android:orientation="horizontal">  <!-- small rectangles. defines whole width -->  <!-- small rectangle (left) --> <relativelayout     android:layout_width="0dp"     android:layout_height="match_parent"     android:layout_weight="1"     android:orientation="vertical">      <textview         android:id="@+id/lblvaluelte"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:enabled="true"         android:gravity="center"         android:text="1317"         android:textstyle="bold" />      <!-- tag indicator -->     <textview         android:id="@+id/lbltaglte"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_marginleft="5sp"         android:layout_marginstart="5sp"         android:gravity="start"         android:text="t"         android:textsize="18sp"         android:textstyle="bold" />      <!-- units -->     <textview         android:id="@+id/lblunitslte"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true"         android:layout_alignparentright="true"         android:layout_marginend="5sp"         android:layout_marginright="5sp"         android:gravity="end"         android:text="&#181;v/m"         android:textsize="18sp"         android:textstyle="bold" /> </relativelayout> <!-- small rectangles. defines whole width -->  <!-- small rectangle (right) --> <relativelayout     android:layout_width="0dp"     android:layout_height="match_parent"     android:layout_weight="1"     android:orientation="vertical">      <textview         android:id="@+id/lblvaluemid"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:enabled="true"         android:gravity="center"         android:text="145"         android:textstyle="bold" />      <!-- tag indicator -->     <textview         android:id="@+id/lbltagmid"         android:layout_width="30sp"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_marginleft="5sp"         android:layout_marginstart="5sp"         android:gravity="start"         android:text="t"         android:textsize="18sp"         android:textstyle="bold" />      <!-- units -->     <textview         android:id="@+id/lblunitsmid"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true"         android:layout_alignparentright="true"         android:layout_marginend="5sp"         android:layout_marginright="5sp"         android:gravity="end"         android:text="&#181;v/m"         android:textsize="18sp"         android:textstyle="bold" /> </relativelayout> 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -