Я пытаюсь установить Padding Top
в значение Specified View
из другого Layout Height
, но Layout
продолжает давать мне значение 0
.Я пытался поместить код в onCreate
и onStart
и onResume
в одно и то же значение.
Пример кода:
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() + "");
}
}
================ Относительно C C Ника Ответ:
спасибо за @C Nick, я нашел решение по его ответу:
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();
}
}
}
и onCreate
inActivity
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());
}
});
и теперь он работает нормально, но я не думаю, что мое решение является оптимальным