I adding View (button) programally in Linearlayout.LinearLayout is layouted by XML in Fragment.
I want to get button width, but always return 0.
I googled thi
I'd had a similar problem and solved it in the Fragment callback onViewCreated() like this:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.post(new Runnable() {
@Override
public void run() {
// do operations or methods involved
// View.getWidth(); or View.getHeight();
// here
}
});
}
run() runs after all views were rendered...