Try this!
Create ScreenWidth.java
public class ScreenWidth {
public ScreenWidth(){}
@SuppressLint("NewApi")
public int getScreenWidth(Context context) {
int columnWidth ;
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
final Point point = new Point();
try {
display.getSize(point);
} catch (java.lang.NoSuchMethodError ignore) { // Older device
point.x = display.getWidth();
point.y = display.getHeight();
}
columnWidth = point.x;
return columnWidth;
}
}
now create object of above class to get screen size pragmatically.
ScreenWidth SW = new ScreenWidth();
int width_sc =SW.getScreenWidth(this);
TextView t1 = (TextView)findViewById(R.id.t1);
t1.setTextSize(((width_sc*22)/768));
Hope this may help you!