Android强制LinearLayout在删除视图后调整视图大小

Android强制LinearLayout在删除视图后调整视图大小,android,android-linearlayout,Android,Android Linearlayout,我有一个带有两个视图的线性布局,视图a占据了一些垂直空间,视图B占据了布局的其余部分 <LinearLayout android:id="@+id/ly2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/input" android:orientation="

我有一个带有两个视图的线性布局,视图a占据了一些垂直空间,视图B占据了布局的其余部分

<LinearLayout

        android:id="@+id/ly2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/input"
        android:orientation="vertical" >

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="50dp" >
        </View>

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

在某些情况下,我想删除视图A。如何让LinearLayout刷新,以便视图B占据整个空间

致以最良好的祝愿

View v=(View)findViewById(R.id.view1);
在某一点上使用

v.setVisibility(View.GONE);
查看此以获取更多帮助

在某一点上使用

v.setVisibility(View.GONE);

有关更多帮助,请参见此

尝试用此代码替换xml

<RelativeLayout

        android:id="@+id/ly2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="50dp" >
        </View>

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>

尝试用此代码替换xml

<RelativeLayout

        android:id="@+id/ly2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="50dp" >
        </View>

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>

使用
setVisibility(View.GONE)使用
设置可见性(View.GONE)我明白了。这是可行的,但是为什么仅仅从布局中删除视图不会更改布局?请尝试
linearLayout.invalidate()删除后
查看
我明白了。这是可行的,但是为什么仅仅从布局中删除视图不会更改布局?请尝试
linearLayout.invalidate()删除后
查看