jay
jay

Reputation: 2032

Multiple views in a Fragment design

I need to use an ImageView, VideoView, WebView, youtubeView to display information on the screen in form of segments. Each segment will display on view at a time. What are the pros and cons of following 2 approaches:

  1. Have a single fragment with above mentioned views, make visible one view at a time on-demand basis, and keep the rest invisible. Whenever there is a requirement of a particular fragment to change into another view, toggle visibility accordingly

  2. Have a separate fragment definition associated with each view, add and remove fragments based on media item to be displayed and coordinates given as input.

Screen must look something like this, where coordinates and sizes of each item change dynamically with time. image

Here (1), (2), (3), (4) denote 4 different items (few images, few videos, webviews, etc) being displayed at any instant.

Upvotes: 0

Views: 634

Answers (1)

CaseyB
CaseyB

Reputation: 25058

Fragments are great for making layouts more flexible, like if you want to use the same code for a phone and a tablet. Or if you want to use tabs or viewpagers. If you're going to have just one arrangement of views then putting them in their own fragments doesn't really buy you much.

Upvotes: 1

Related Questions