0

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 my Surface View I set it to be Visible.

This layout should contain one Textview and should be scrollable

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

2: How can I achieve this in Code?

It should be:

Scrollable. Should be a certain Size: Half of the screen width and half of the screenHeight So it also should be at the position screenWidth/4 and screenHeight/4 To achieve this I can set these parameters inside my mainThread that is attached to the surfaceview so I have the parameters needed allready in Pixel format that's no Problem. 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.

So it should go like this:

User taps the button to display the menu Now the User can scroll through the Menu When he presses the Backbutton or outside of the View It should close itself When there is a new Text that should be displayed it should be attached to the layout to be ready to be displayed at the next time the user clicks the button again

Thank you

Ilja KO
  • 1,272
  • 12
  • 26

1 Answers1

0

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.

Community
  • 1
  • 1
Gennadii Saprykin
  • 4,505
  • 8
  • 31
  • 41
  • Thanks for the answer unfortunately I want to avoid messing around with fragments...cant I do it with normal views that I set visible or invisible this is much less work I think – Ilja KO Aug 04 '15 at 02:10
  • You can do it without fragments but it will be more complicated.. 1. You will have to handle saving state and views on rotations 2. You will have to handle back button click 3. You will have to handle touch outside 4. UI issues such as it won't look like a native dialog, at least elevation 5. all code will go to activity which is bad. 6. Complicated activity layout. I don't see any advantage of not using dialog fragment here – Gennadii Saprykin Aug 04 '15 at 03:45
  • I'm allready handling rotation and back button. I do this in all my apps so its ok. I'm also completely handling all touch events whatsoever. And all code goes into a thread I dont do anything except initialisation on Activity(except from code that must be done on activity but then it is just a runOnUiThread) – Ilja KO Aug 04 '15 at 12:11
  • I really jsut want to add a Viewgroup into my framelayout that can show a scrollable list thats all :) – Ilja KO Aug 04 '15 at 12:13
  • sorry, I don't agree with you :) I don't understand why you need all these hacks and avoid dialog fragments. Is there any advantage? It seems you already know what you want to do.. Whats your question then? – Gennadii Saprykin Aug 04 '15 at 14:57
  • I wanted a listview in my App thats all. Fortunately I have managed to get exactly what I wanted. It's no hack jsut a Viewgroup I want to Display lol and thats what I got now...Fragments have their advantage but thats overkill to set up a fragment to only display one little Textview dont you think? – Ilja KO Aug 04 '15 at 15:31
  • Now I have what I want and I can slide the listView over my surfaceview and add strings to it and it works just fine now ;) – Ilja KO Aug 04 '15 at 15:34
  • nah what do I need that for? I amrked your one – Ilja KO Aug 04 '15 at 16:11