Consider this simple example:
I have a single line text like this: "Hello"
I wanna measure this text using StaticLayout. So I wrote something like this:
StaticLayout layout = new StaticLayout("Hello", myTextView.getPaint(), myTextView.getWidth(), Layout.Alignment.NORMAL, 1, lineSpace, false);
In above code I changed lineSpace variable in a for loop and every time log the layout's height:
for(int lineSpace=0; lineSpace<20;lineSpace++){
StaticLayout layout = new StaticLayout("Hello", myTextView.getPaint(), myTextView.getWidth(), Layout.Alignment.NORMAL, 1, lineSpace, false);
Log.d("TAG", "layout height: " + layout.getHeight());
}
When I run this code on device with android M layout't height doesn't changed with multiple values of lineSpace. But in lower android versions layout's height changed with line space respectively.
Although when your text is more than one line ,StaticLayout consider line space between two lines. But it seems Android M doesn't consider line space for last line but lower Android versions does.
My question is this: After what version of android StaticLayout consider line space for last line? Can I wrote something like this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// in this version StaticLayout don't consider line space for last line
} else {
// in this version StaticLayout consider line space for last line
}