1

Hello I have an surfaceview in my app.All my games are built like this:

Instanciating a subclass of Surfaceview which implements the SurfaceHolder.Callback interface.

Now is that I want to open a menu when I click on a Button(custom made object) This should bring up a fragment with a scrollable textview( I thought of just a listview with one textview element inside it because I think the textview alone is not scrollable if the text is very long..any contrary arguments are welcome)

but how do I do this?

I have allready a Fragment class and a layout for the fragment

Edit 3:

Ok I've managed to set the SurfaceView programmatically like this:

   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(savedInstanceState==null)
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                             WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        prefs=getSharedPreferences("myPrefs",0);
        mView=new MainView(this);
        loadSharedPrefs();

        LinearLayout myLayout = (LinearLayout)findViewById(R.id.main);

        mView.setLayoutParams(new LinearLayout.LayoutParams(
                                             LinearLayout.LayoutParams.MATCH_PARENT,
                                             LinearLayout.LayoutParams.MATCH_PARENT));
        myLayout.addView(mView);
    }
}

where the layout is just a blank linearlayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" 
android:id="@+id/main">
</LinearLayout>

So for now I just need a Fragment to be displayed when I click a Button

Here the Fragment Class so far:

public class HintListFragment extends Fragment
{


 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.hintlist, container, false);
    }
}

and the layout for this fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView 
    android:id="@+id/hintList"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="sagdjsahgdhascxasbcxahsgdhsagdhasgdashgdsajsgdh"

    />


</LinearLayout>
fadden
  • 51,356
  • 5
  • 116
  • 166
Ilja KO
  • 1,272
  • 12
  • 26

1 Answers1

0

In your layout, wrap the surfaceview and a fragment in a FrameLayout. Make sure the fragment is on top of the surfaceview and then set the fragment's visibility to GONE. When you want to show the fragment, just set the visibility to VISIBLE

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <SurfaceView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <com.example.MyFragment
        android:visibility="gone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_gravity="center"
        android:id="@+id/myfragment"/>
</FrameLayout>
d0nut
  • 2,835
  • 1
  • 18
  • 23
  • Pleasr just edit your question instead of forcing me to prettyprint your code – d0nut Aug 03 '15 at 19:18
  • 1
    @IljaKO Im sorry but i dont really know what you're asking. I just told you how to adjust your layout to allow for a fragment to appear on top of your surfaceview. What do you need help with understanding? – d0nut Aug 03 '15 at 19:21
  • well I don't know how to build the xml layout and attach it to the activity unfortunately allthough I'm doing android now for 10 months lol I failed doing this thing (see edit 2 in my question) – Ilja KO Aug 03 '15 at 19:26
  • 1
    R.layout.main is your layout file. Make the changes there. Additionally, I would read up on how to do layout work in android because it's a very vital part of building apps. It makes it pretty braindead easy to make massive changes to your layout – d0nut Aug 03 '15 at 19:29
  • I have the problem that I now attached the layout main to my activity but it is jsut blank...I thought it would fire up my constructor but it doesnt do so....I added 2 more constructors but nothing works the main thread doesnt gets initiated....what should I do for beginners I just want to have a SurfaceView be displayed correctly – Ilja KO Aug 03 '15 at 19:36
  • 1
    You should use the layout. it will call the empty constructor in your surfaceview. – d0nut Aug 03 '15 at 19:37
  • Do you mean my layout? But it should not call the blank constructor(I dont have one either...maybe thats why null) – Ilja KO Aug 03 '15 at 19:41
  • 1
    @IljaKO When i finally get home later, i'll try to answer your question more in depth but at the moment i'm kind've busy. Just know that the layout will use your empty constructor in the surfaceview (so you'll need to change how that works) but layout files are probably the easiest ways to do it. You can, additionally, load views into your layout programmatically and fragments using the fragment manager. – d0nut Aug 03 '15 at 19:42
  • 1
    @IljaKO You do have a blank constructor. It's implicitly defined in the super classes – d0nut Aug 03 '15 at 19:42
  • Thats exactly what I want I want to load all that stuff programmatically into my linearlayout or relative or so I dont care what ViewGroup.....I just want it like this: Create the MainView....create the Fragment....add it to the activity layout...voila done!!! .But the Problem is also as soon as the View is created the mainthread is created inside the mainview and starts to draw but I think that wont happen untill I set the content of the activity with my viewgroup right? – Ilja KO Aug 03 '15 at 19:47
  • when i say the main view is created I mean when the Surface is created and the m,ethod onSurfaceCreated() is being called – Ilja KO Aug 03 '15 at 19:48
  • 1
    @IljaKO try to stay somewhat professional on here. I said I would help you when I get home – d0nut Aug 03 '15 at 19:49
  • all right I've managed to set the surfaceview programmatically see Edit 3! – Ilja KO Aug 03 '15 at 20:23
  • Hey @iismathwizard I have decided to do it in another approach you could help me out here :http://stackoverflow.com/questions/31797105/how-to-add-a-layout – Ilja KO Aug 03 '15 at 21:39
  • Now I managed to display a Textview above the surfaceview so far but thats not what I want I amrked your question as right because you helped me a lot with the framelayout tip ;) – Ilja KO Aug 03 '15 at 21:40