0

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?

Joey Harwood
  • 961
  • 1
  • 17
  • 27
  • What is the "marker" that's visible? Also, is there a reason you are doing this programmatically rather than by XML? Typically for simple layouts XML makes everything easier. – Joey Harwood Nov 17 '17 at 19:09
  • i want to display only when some picture(or more) is visible in display(marker), and sometimes, may have more than one text, so i dont thing XML works in this case – Gustavo Hiroki Nakagawa Nov 18 '17 at 21:56

1 Answers1

0

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 );

trocchietto
  • 2,607
  • 2
  • 23
  • 36