2011-04-30 123 views
0

我有以下布局。我使用的是layout_weight =“1”,这样所有的东西都会拉伸以适应屏幕的统一。用户可以选择删除图像,基本上设置visibility =“gone”。拉伸布局到屏幕

假设用户在中间的LinearLayout中删除了两个图像,我希望该布局消失。目前,如果您删除两张图片,则空白布局会保留在那里,并留下空白。我怎样才能使它正常工作,以便其他布局填充空白空间?

<LinearLayout android:orientation="vertical" android:width="fill_parent" android:height="fill_parent"> 
    <LinearLayout android:orientation="horizontal" android:layout_weight="1"> 
     <Image></Image> 
     <Image></Image> 
    </LinearLayout> 
    <LinearLayout android:orientation="horizontal" android:layout_weight="1"> 
     <Image></Image> 
     <Image></Image> 
    </LinearLayout> 
    <LinearLayout android:orientation="horizontal" android:layout_weight="1"> 
     <Image></Image> 
     <Image></Image> 
    </LinearLayout> 
</LinearLayout> 

回答

0

你会想在Java代码中做到这一点。在代码中,将LinearLayout(View的子类)设置为不可见。

LinearLayout layout1 = this.findViewById(R.id.linearLayout1); 
//Some logic here to determine if the images in that layout have been removed or not 
//if they gone then.. 
layout1.setVisibility(View.INVISIBLE); 

就是这样的。你也可能想看看这是否扩大了现有布局,以弥补它留下的空白。我没有测试过,但我猜这可能会解决你的解决方案? :-)