I am trying to set Padding Top to Specified View from another Layout Height, but the the Layout keeps giving me 0 value.
I’ve tried to put the code in onCreate and onStart and onResume its the same value.
Sample of the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen_layout);
EditText editText = (EditText) findViewById(R.id.editText1);
editText.setPadding(0, findViewById(R.id.main_screen_banner_linearLayout).getBottom(), 0, 0);
System.err.println("Bottom:" + findViewById(R.id.main_screen_banner_linearLayout).getHeight() + "");
}
}
================
Regarding for C Nick Answer:
thanks for @C Nick
i made a solution by his answer:
public class CustomTextView extends TextView {
Runnable runnable;
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (runnable != null) {
runnable.run();
}
}
}
and onCreate in Activity
final CustomTextView customTextView = (CustomTextView) findViewById(R.id.editText1);
customTextView.setRunnable(new Runnable() {
@Override
public void run() {
System.out.println("Height:" + findViewById(R.id.main_screen_banner_linearLayout).getHeight());
customTextView.setPadding(customTextView.getPaddingLeft(),
findViewById(R.id.main_screen_banner_linearLayout).getHeight(),
customTextView.getPaddingRight(), customTextView.getPaddingBottom());
}
});
and now it works fine, but i dont think my solution is optima
You will need to set the padding sometime after the layout pass occurs. You can probobly override the onLayout of your EditText, and there set the padding because the View should be layed out and measured by then.
This is a decent resource for the layout/measure/draw workflow.
How Android Draws