Monday 12 January 2015

Get width of button in layout at runtime.

 Simple code snippet Get width of button in layout at runtime. 

final ViewTreeObserver observer = openButton.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
widthButton = openButton.getWidth();
tXWidth = width - widthButton;
frameLayout.setTranslationX(tXWidth - leftMargin);
}
});

No comments:

Post a Comment