Michael Chourdakis
Michael Chourdakis

Reputation: 11158

Android force LinearLayout to resize views after view removal

I 've a LinearLayout with 2 views, view A which takes some vertical space, and view B which takes the rest of the layout.

<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>

At some point I want to remove view A. How do I tell LinearLayout to refresh so view B takes the entire space?

Best Regards.

Upvotes: 0

Views: 1618

Answers (2)

Maniya Joe
Maniya Joe

Reputation: 801

try to replace your xml with this code

<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>

In your main activity where this xml is used put this

View view=(View)findViewById(R.id.view1);
view.setVisibility(View.GONE);

Upvotes: 2

N J
N J

Reputation: 27505

View v=(View)findViewById(R.id.view1);

at some point use

v.setVisibility(View.GONE);

see this link for more help

Upvotes: 3

Related Questions