I was needing to get the value of the gravity of a LinearLayout. I checked the documentation and I only found how to set it ( setGravity(value) ).
getGravity ()
https://developer.android.com/reference/android/widget/LinearLayout.html#getGravity()
using reflection:
int gravity = -1;
try {
final Field staticField = LinearLayout.class.getDeclaredField("mGravity");
staticField.setAccessible(true);
gravity = staticField.getInt(linearLayout);
//Log.i("onFinishInflate", gravity+"");
}
catch (NoSuchFieldException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalAccessException e) {}