androidartoolkit

Show a TextView in a FrameLayout


I'm trying to show a TextView in a FrameLayout when the marker is visible.

Like in the code below:

                FrameLayout frameLay = new FrameLayout(context);
                FrameLayout.LayoutParams layoutParamsFrame = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);

                frameLay.setLayoutParams(layoutParamsFrame);

                TextView theText = new TextView(context);
                theText.setText("text_test");
                theText.setTextColor(Color.WHITE);
                theText.setTypeface(Typeface.DEFAULT_BOLD);

                LayoutParams layoutParamsText = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                theText.setLayoutParams(layoutParamsText);
                theText.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);

                first = true;

                frameLay.addView(theText);

This does not work for me. The marker is visible and I execute this code, but nothing happens. How can I fix this?


Solution

  • you can read this post it is explained how to add a TextView to a FrameLayout

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
    
    ((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText, params);
    

    So basically you have to add to addView two parameters so becomes

    frameLay.addView(theText,layoutParamsText );