Pwnna
Pwnna

Reputation: 9538

Android collapse an element?

Is it possible to "collapse" (in my case, width=0, and the element to the left of it will expand and take its place) an element (in my case an ImageView) in Android ui when it's been set to invisible?

Upvotes: 0

Views: 1555

Answers (3)

Chris Noldus
Chris Noldus

Reputation: 2502

If you are using the right layout, you can apply a positive weight to both elements with layout_width=match_parent. Fiddle with the weights until they look right.

When you want one to disappear just call .setVisibility(View.VISIBILITY_GONE). The element will vanish and the other one will fill the missing space.

Upvotes: 2

user849998
user849998

Reputation:

try to remove the old version of view and instead of that one add a new one

RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.child);
item.addView(child);

Upvotes: 0

skynet
skynet

Reputation: 9908

Couldn't you just use setVisibility(View.GONE)? That will make the view take up no space and other views will take up the space it occupied.

Upvotes: 0

Related Questions