Skip to content Skip to sidebar Skip to footer

How To Add A Layout

Hello I want to add a LAyout to my Activity. I have a FrameLayout where I add a SurfaceView so far. Now I want to add another Layout as a menu over it so when I click a Button on m

Solution 1:

1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Textviews dynamically

That sounds good to me, you can go with either ListView or RecyclerView. You are basically not adding TextViews dynamically, you create an adapter that will do handle creating and recycling of views for you.

2: How can I achieve this in Code?

Create a DialogFragment, it's the best candidate for such dialogs with logic. Its lifecycle is handled via FragmentManager, so you won't have issues on screen rotations and so on. It allows you setting whatever layout you need just like any other Fragment. It will be placed in the center for you, so you don't have to handle that manually. Just set the size of the dialog you want and it will look perfect.

It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.

I don't really get this one. When user touches outside, do you need to lose the focus but the dialog should not be closed? If yes, then this is already answered here:

Allow outside touch for DialogFragment

If the dialog should be closed, you don't have to implement anything, it works like that by default.

Post a Comment for "How To Add A Layout"