我有2个接壤textviews垂直居中地和水平地并排,因为它是下面的图像中显示:“布局或其父项无用”。如何避免这种情况?
在每个这些2个textviews的顶部,我必须添加一个“T '左下方的textview和右下角的单位('uV/m')。要做到这一点,我结束了以下布局XML代码:
<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="µ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="µV/m" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
所以:
- 第一级:layout_small_rectangle让我垂直居中;
- 第二级别:权重为1的2 RelativeLayout允许我将2个文本浏览与水平边界均匀分布;
- 第三层:相对布局,允许我对齐左/右边框文本视图中的'T'和'UV/m'文本视图;
我的问题:是否有可能避免IDE警告说'布局是无用的',由级别2和3的连续RelativeLayout造成的?
我试过你的解决方案,它不工作,因为2 textviews矩形不在屏幕中间互相触摸。在某处,我想你需要指定它们的宽度(drv3lite_small_rectangle_width)... – Danuc
...我的意思是“**现在**互相触摸......” – Danuc