Android的layout_below不工作 [英] Android layout_below not working

查看:222
本文介绍了Android的layout_below不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序大量使用RelativeLayouts和想我知道如何指定它们,但是这有我不知所措。我基本上定位4 TextViews在二两行,每行包括标签和文本将被提供的。它看起来应该是这样的:

I use RelativeLayouts extensively in my app and thought I knew how to specify them, but this has me at a loss. I am basically positioning 4 TextViews in two rows of two each consisting of a label and text that will be supplied. It should look something like:

出生:1810年8月23日梅森有限公司,肯塔基州

Born: 23 Aug 1810 Mason Co., Kentucky

卒于:1865年7月15日辛辛那提,汉密尔顿有限公司,俄亥俄州

Died: 15 Jul 1865 Cincinnati, Hamilton Co., Ohio

这是布局的相关部分:

        <TextView android:id="@+id/birth_lbl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/given_layout"
            android:layout_alignLeft="@+id/given_layout"
            android:layout_marginTop="6dip"
            style="@style/label"
            android:text="@string/born"
        />
        <TextView android:id="@+id/birth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/birth_lbl"
            android:layout_alignBaseline="@+id/birth_lbl"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="6dip"
            style="@style/main_text"
            android:text="dd Mmm yy"
        />
        <TextView android:id="@+id/death_lbl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/birth"
            android:layout_alignLeft="@+id/birth_lbl"
            android:layout_marginTop="4dip"
            style="@style/label"
            android:text="@string/died"
        />
        <TextView android:id="@+id/death"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/death_lbl"
            android:layout_alignLeft="@+id/birth"
            android:layout_alignBaseline="@+id/death_lbl"
            android:layout_marginRight="6dip"
            style="@style/main_text"
            android:text="dd Mmm yy"
        />

由于某些原因,这显示上述诞生行意见生死一线的意见!如果我改变了看法death_lbl的规范,而不是被'layout_below =@ + ID / birth_lbl',该行被正确定位!但是,它是可能的出生,以换到多行,所以我真的需要二号线位置以下的诞生,而不是birth_lbl。

For some reason, this displays the death line views ABOVE the birth line views! If I change the spec of the death_lbl view to instead be 'layout_below="@+id/birth_lbl"', the lines are positioned correctly! However, it is possible for the "birth" view to wrap to multiple lines, so I really need to position the 2nd line below "birth", not "birth_lbl".

任何人都知道这种行为的原因是什么?它既在Eclipse图形布局编辑器,并在运行Android 4.0平板电脑我发生运行

Anyone know the reason for this behavior? It occurs both in the Graphical Layout editor in Eclipse and at runtime on my tablet running Android 4.0.

推荐答案

试着改变的android:layout_below =@ + ID /诞生 death_lbl 的android:layout_below =@ ID /诞生,因为此时它已经宣布,该 + 暗示,它可能会导致问题再次声明,当它。

Try changing android:layout_below="@+id/birth" in death_lbl to android:layout_below="@id/birth", because at this point it is already declared, which the + implies, it could lead to problems when declaring it again.

这篇关于Android的layout_below不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆