java为什么我不能在相对布局中的另一个视图上方看到文本视图?
我有一个xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical"
安卓:paddingLeft="8dp"
安卓:paddingRight="8dp" >
<TextView
安卓:id="@+id/errorMsg"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_above="@+id/pointsText"
安卓:visibility="gone"/>
<TextView
安卓:id="@+id/pointsText"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_above="@+id/offers_list"
安卓:text="you have 100 points"
安卓:visibility="visible"/>
<ListView
安卓:id="@+id/offers_list"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:drawSelectorOnTop="false"
安卓:dividerHeight="0dp"
安卓:divider="#00000000"/>
</RelativeLayout>
但我无法在eclipse图形预览器中看到pointsText
我错过了什么
# 1 楼答案
如果这是活动中的一个片段,您可能需要检查例如AppBarLayout和添加片段的布局的嵌套
# 2 楼答案
你有
对于你的
TextView
,但是你没有任何关于ListView
的定位。由于默认情况下RelativeLayout
会将其孩子放在左上方,因此ListView
将位于顶部,并且在其上方没有任何地方可以放置TextView
尝试从
TextView
中删除该属性并添加在你的
ListView
上我刚刚测试了这个,它确实有效。我可以看到列表上方的pointsText
TextView
。因此,您需要对错误TextView
做一些不同的处理,或者当您想要更改它的visibility
时,您很可能会遇到同样的问题有点离题
RelativeLayout
没有orientation
属性,所以这对你没有任何好处,但也不会对你造成任何实际伤害# 3 楼答案
使用相对布局时,布局元素彼此重叠。为了避免这种情况,您应该相对其他布局放置元素。让你的代码像这样
现在,您将能够看到您的所有布局