Jeris
Jeris

Reputation: 2473

Replacing views dynamically without changing activity

I would like to know how to go about doing this small problem that I am encountering while making a video player app. First

On clicking the first control(the rectangular icon) in the above image the following view must be displayed instead of it which I am quite unsure as to how to do it. Here is what it is replaced by Second

Also please note, by any chance the activity should not be changed. I have been able to design the views individually but having problem changing them at runtime when user clicks. Could someone go about explaining as to how it can be done or provide some suitable links to achieve my goal. Thanks.

Upvotes: 2

Views: 1461

Answers (3)

Lucas Arrefelt
Lucas Arrefelt

Reputation: 3929

For something as simple as this you can just change the visibility of the views.

view.setVisibility(View.INVISIBLE)

Or the more effective:

view.setVisibility(View.GONE)

Do that on the views you want gone, I suggest a wrapper class. It's either this or changing the contentView as describded below.

Upvotes: 2

AndreiBogdan
AndreiBogdan

Reputation: 11164

This might be a stupid solution, 'cause i'm terribly tired right now, but why not use the bringToFront() method on the View that you want to display in the front? Display them both in front of each other, maybe in a RelativeLayout, and then swap between them as you wish. They are small objects, so don't consume memory. I don't see why this shouldn't work.

OR

Place them above one another, so they overlap and then make the above view visible/invisible depending on which one you need to display.

OR

just remembered I read somewhere that you can scroll through a ScrollView automatically from code. So display both Views in a ScrollView in succession and when pressing the button or whatever, you scroll down to make the next menu visible. When pres back, you scroll up to make the previous thing available. Should work, and might also make a nice animation between changing of the menus.

Upvotes: 0

Simon
Simon

Reputation: 14472

this.setContentView(R.layout.newLayoutToUse);

However, I have a feeling there is a better way to do what you want. It's overkill to load a complete new layout if you just want to change the image of some buttons or imageviews.

Upvotes: 0

Related Questions