问题RelativeLayout的时候查看能见度View.GONE能见度、时候、问题、GONE

2023-09-06 01:39:27 作者:°迷人的琥珀色。

我有一个 RelativeLayout的是这样的:

<RelativeLayout>
<TextView1/>
<TextView2/> // <-- View.VISIBLE OR View.GONE
<TextView3/>
<TextView4/>
</RelativeLayout>

每个的TextView 是挂靠低于previous 的TextView 安卓layout_below

Each TextView is anchored below the previous TextView with android:layout_below.

问题是,TextView2可能会或可能不会有(或 View.VISIBLE View.GONE ) ;如果是 View.VISIBLE ,那么一切都很好,但如果它的 View.GONE ,然后TextView3最终被渲染上TextView1的顶部

The problem is that TextView2 may or may not be there (either View.VISIBLE or View.GONE); if it's View.VISIBLE, then all is fine, but if it's View.GONE, then TextView3 ends up being rendered on top of TextView1.

我已经试过各种方法来解决这个问题,但每次我抓出由 RelativeLayout的的'你不能引用一个id之前,它的定义的规则。

I've tried various ways to fix this, but each time am caught out by RelativeLayout's 'you cannot reference an id before it's defined' rule.

我希望我失去了一些东西明显在这里。

I'm hoping that I'm missing something obvious here.

推荐答案

您可以将在LinearLayout中TextView的2和3,保持线性布局下面的TextView 1。

You can place textview 2 and 3 in the LinearLayout and keep the linear layout below textview 1.