layout_above被破坏了吗?这个简单的布局快把我逼疯了

问题描述:

这里是我的代码layout_above被破坏了吗?这个简单的布局快把我逼疯了

<TextView 
    android:id="@+id/BIG" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="BIG" 
    android:textSize="50dp" /> 

<TextView 
    android:id="@+id/small" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@id/BIG" 
    android:layout_toRightOf="@id/BIG" 
    android:text="small" 
    android:textSize="10dp" 

    /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/small" 
    android:layout_alignLeft="@id/small" 
    android:text="small above" 
    android:textSize="10dp" /> 

这是我得到的结果(实际截图)。正如你所看到的,整个文本视图已经消失。

screenshot

这就是我想要的结果(上MSPAINT编辑)

enter image description here

我不能使用,因为自动填充ALIGN_BOTTOM。这里是什么样子,如果我改用align_Baseline(实际截图)的ALIGN_BOTTOM已经进行的所有其他垂直对齐后,进行

enter image description here

+0

在第三个文本视图中添加android:layout_toRightOf =“@ id/BIG” – 2015-03-02 22:11:04

+0

您的父元素是一个'RelativeLayout',对吧? – tachyonflux 2015-03-02 22:11:07

+0

@karaokyo是的。 – user3453281 2015-03-02 22:14:00

显然基线对齐。
所以“小于”排列在以上“小”当它仍然在其默认位置。然后,“小”与“BIG”的基线对齐,并留在“小于上方”之外,位于RelativeLayout的顶部。

解决这个问题的一个可能的解决方案是将两个较小的TextView包装在一个LinearLayout中,然后可以与左侧较大的TextView进行正确的基线对齐。
并添加机器人:baselineAlignedChildIndex = “1”到的LinearLayout,让第二个孩子的基线对齐到 “大”

参考:http://scottweber.com/2014/02/06/working-with-baselines-in-relativelayout/

+0

谢谢! android:baselineAlignedChildIndex =“1”是拼图的缺失部分。 – user3453281 2015-03-02 22:39:52

试试这个:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<TextView 
    android:id="@+id/BIG" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="BIg" 
    android:textSize="50sp" 
    android:layout_gravity="bottom" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_gravity="bottom"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="small above" 
     android:textSize="10sp" /> 

    <TextView 
     android:id="@+id/small" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="small" 
     android:textSize="10sp" /> 


</LinearLayout> 

并使用sp代替文本大小的dp。

+0

我不能使用小写字母g,这就是为什么我必须使用align_Baseline – user3453281 2015-03-03 15:11:20