[英]Android layout_below not working
我在我的应用程序中广泛使用RelativeLayouts,并认为我知道如何指定它们,但这让我感到茫然。 我基本上将4个TextView放在两行,每行两行,每行包含一个标签和将要提供的文本。 它应该看起来像:
出生:1810年8月23日,肯塔基州梅森公司
死了:1865年7月15日辛辛那提,俄亥俄州汉密尔顿公司
这是布局的相关部分:
<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”。
有人知道这种行为的原因吗? 它出现在Eclipse的Graphical Layout编辑器和运行Android 4.0的平板电脑的运行时。
尝试将android:layout_below="@+id/birth"
death_lbl
为android:layout_below="@id/birth"
,因为此时它已经被声明, +
暗示,它可能会在再次声明时导致问题。
我也遇到了同样的问题,因为我使用的是约束布局,但align_below仅适用于相对布局 。 所以检查你正在使用的布局。
如果修复你的+
符号没有帮助,你可以随时将你的id/death
定位在id/birth
之下,然后将id/death_label
置于leftOf id/death
。
我实际上能够通过仅使用那些字段编写临时layout
来复制这种现象,并且如果我没有将初始birth_lbl
视图相对birth_lbl
视图定位,则能够确定问题消失了(“given_layout”在此案件)。
所以我不确定这是否被归类为修复,变通方法或者kludge(现在仍然是一个词?),但我所做的是将文本视图放在他们自己的RelativeLayout
并定位RelativeLayout
相对到id/given_layout
。 无论如何,它有效......
您的问题是您在相对布局上调用属性,就好像您再次声明它一样。
当您为视图声明ID时,它应该像这个android:id="@+id/button"
并且当您希望Android将该特定视图放置在相对布局中的任何其他视图的上方或下方时,您必须调用它喜欢这个android:layout_below="@id/textview"
这告诉android你声明了一个带有id按钮的按钮并希望它位于textview下面,记住不要使用@+id
来定位视图使用@id
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.