我有一个父RelativeLayout,其中有其他 View 和其他相对布局。当我尝试使这些相对布局之一具有 GONE
可见性时,它不会消失。有什么解决办法吗?我将发布我想要的布局GONE
。
<RelativeLayout android:id="@+id/relativeLayerA"
android:layout_width="315px"
android:layout_height="35px"
android:background="@drawable/bgnavyblue_abcd"
android:layout_below="@id/relativeConfig1"
android:layout_toRightOf="@id/relativeRecipe"
android:layout_marginLeft="15px"
android:layout_marginTop="20px"
>
<ImageView android:id="@+id/imgIconA"
android:layout_width="33px"
android:layout_height="33px"
android:src="@drawable/icon_a"
android:layout_alignParentLeft="true" <!-- -->
/>
<TextView android:id="@+id/txtLayerA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/layer_a_adjusts"
android:textSize="7pt"
android:textColor="#FEFEFE"
android:typeface="sans"
android:layout_toRightOf="@id/imgIconA"
android:layout_marginLeft="5px"
android:layout_marginTop="8px"
/>
</RelativeLayout>
以下是完整代码:http://pastebin.com/VhpWSa6Z 请问有人知道这是怎么回事吗?
编辑:有人说这可能会发生,因为其他 View 正在使用此 View 将自己定位在屏幕上。所以我尝试将RelativeLayerC 设置为GONE
可见性。它起作用了。我不明白为什么它适用于该 View ,而不适用于RelativeLayerA。在这里您可以看到使用RelativeLayerC作为引用的RelativeConfig4。 http://pastebin.com/uHW6faPy
最佳答案
我也遇到了同样的问题..我认为这是一个错误..:( 不过你可以绕过它..尝试这个使RelativeLayout不可见。
RelativeLayout rLayout=(RelativeLayout) findViewById(R.id.//your relativeLayout id);
RelativeLayout.LayoutParams rParams = new RelativeLayout.LayoutParams(
0, // its height... set it 0 to make it invisible..
RelativeLayout.LayoutParams.FILL_PARENT // and its width
);
rLayout.setLayoutParams(rParams);
这是为了使其可见。
RelativeLayout.LayoutParams rParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
rLayout.setLayoutParams(rParams);
以下是 xml 中relativelayout的正确参数。
<RelativeLayout
android:id="@+id/rLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#AA000000" >
记住!不要使用这个。
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
或者向左,向右..否则它将无法工作..!
希望有帮助。
关于java - 使用 View.GONE 时,RelativeLayout Visibility 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8707719/