我有一个RelativeLayout视图,还有3个子视图。我试图在代码中使用setVisibility将相对布局设置为INVISIBLE来隐藏它们所有。有趣的是,当我使用setVisibility(View.INIVISIBLE)时,只有第一个子视图被隐藏了,而其他两个没有被隐藏。所以我有点困惑 - 如果我将父视图设置为不可见,它不应该改变所有子视图的可见性或让它们保持原样吗?
请随意指向一个解释这个问题的参考页面 - 我找不到任何东西。
更新:我尝试将其设置为View.GONE,但是发生了同样的事情,除了仍然可见的两个子元素会向上移动一点。
以下是相关的XML:
请随意指向一个解释这个问题的参考页面 - 我找不到任何东西。
更新:我尝试将其设置为View.GONE,但是发生了同样的事情,除了仍然可见的两个子元素会向上移动一点。
以下是相关的XML:
<RelativeLayout
android:id="@+id/optionsform"
android:layout_width="fill_parent"
android:padding="8dp"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvoptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/tvoptions"
android:textColor="#f000"
android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="bold"/>
<TextView
android:id="@+id/tvdictionary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tvoptions"
android:layout_marginLeft="30dp"
android:layout_marginTop="16dp"
android:text="@string/dictionary"
android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#f000" />
<Spinner
android:id="@+id/dictionary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/tvdictionary"
android:layout_alignParentRight="true"
android:layout_marginTop="-10dp"
android:layout_marginLeft="6dp"
android:layout_toRightOf="@+id/tvdictionary" />
</RelativeLayout>
以下是我使用的相关代码:
public void onClick(View v) {
//Toggle viewing of options, using "if" in case it is set to View.GONE
View view = findViewById(R.id.optionsform);
if (view.getVisibility() == View.VISIBLE)
view.setVisibility(View.INVISIBLE);
else
view.setVisibility(View.VISIBLE);
}