I am trying to convert my Android app to Fragments in order to support multiple screen sizes and correctly use the new ICS tabs. I used to use the onWindowFocusChanged() method and run the following code inside it - basically it did some dynamic formatting of my layout after it was created.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout theLayout = (LinearLayout)inflater.inflate(R.layout.tab_frag2_layout, container, false); getWidthEditButton = (ImageButton) theLayout.findViewById(R.id.buttonEditPoints); buttonAddPointsManual = (ImageView) theLayout.findViewById(R.id.buttonAddPointsManual); linearPointsUsed = (LinearLayout) theLayout.findViewById(R.id.linearLayoutPointsUsed); int paddingLeftForTracker = linearPointsUsed.getPaddingLeft(); int paddingRightForTracker = getWidthEditButton.getWidth(); linearPointsUsed.setPadding(paddingLeftForTracker, 0, paddingRightForTracker, 0); }
Now that I have switched to fragments, and for some reason my paddingRightForTracker returns 0. I encountered a problem earlier when I tried to get the width too early, so my transition to onWindowFocusChanged earlier, but this is not available for fragments. It is strange that paddingLeftForTracker actually returns a nonzero value.
If I install paddingRightForTracker manually, this change happens, so I know the code works. I just can't understand why my getWidth returns 0.
Any help would be greatly appreciated.
mattdonders
source share