get layout height and width at run time android

Suppose I have to get a LinearLayout width defined in XML. I have to get reference of it by XML. Define LinearLayout l as instance. l = (LinearLayout)findviewbyid(R.id.l1); ViewTreeObserver observer = l.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // TODO Auto-generated method stub init(); l.getViewTreeObserver().removeGlobalOnLayoutListener( this); } }); protected void init() { int … Read more

How to stretch three images across the screen preserving aspect ratio?

Got it working! But as I said above, you need to create your own class. But it is pretty small. I created it with the help of this Bob Lee’s answer in this post: Android: How to stretch an image to the screen width while maintaining aspect ratio? package com.yourpackage.widgets; import android.content.Context; import android.util.AttributeSet; import … Read more