java - How to get margins of a TextView? -


I'm trying to get the top and left margin of a textview that gave me a hardcode margin

Why am I doing this? Because I want to loop through all the text scenes that I have placed under this text view, so that I will add radioactive groups on these exact margin of programmatic.

  textView [0] = new text view (context); RelativeLayoutParams = New Relative Layout Layout side (relative layout layout paragraph WRAP_CONTENT, relative layout. Layoutpam. WRAP_CONTENT); TextView [0] .setId (1); // 0 to 1 textview [0] .setText (name [0] has been replaced with ID. To apply ()); RelativeLayoutParams.setMargins (24, 39, 0, 0); Int tyo = relativeLayoutParams.getTop (); // Try to get the top margin  

OK, you just do it in another way Just get the layout parameter.

  Relative layout. Layout: lp = (Relative Layout. LayoutParams) textView.getLayoutParams ();  

Then you can use margins through global variables.

  lp.topMargin lp.leftMargin lp.bottomMargin lp.rightMargin  

Comments