删除小部件并以编程方式向上移动整个布局



我有一个活动包含一些带有内部按钮的图像视图。如果发生事件,我删除视图顶部的第一个按钮,例如:

myImageView.setVisibility(View.GONE);

但是,这样我就有一个空白的图像视图,当这种情况下,整个布局都向上移动(因此,空白空间不会出现)。这是FIRS的XML两个ImageView:

<ImageView
    android:id="@+id/facebook_opponent_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/button_facebook" />
<ImageView
    android:id="@+id/numbers_opponent_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="53dp"
    android:src="@drawable/button" />

FacebookOpponentButton是应该消失的。也许我的问题是其他ImageView具有

android:layout_marginTop="53dp"

属性?

您不应在此处使用marginTop属性。而是在下面设置 numbers_opponent_button facebook_opponent_button并删除layout_alignparenttop属性。

继续这样做:

<ImageView
android:id="@+id/facebook_opponent_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/button_facebook" />
<ImageView
android:id="@+id/numbers_opponent_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/facebook_opponent_button"
android:src="@drawable/button" />

最新更新