What is meant by Ems? (Android TextView)
android:ems
or setEms(n)
sets the width of a TextView to fit a text of n 'M' letters regardless of the actual text extension and text size. See wikipedia Em unit
but only when the layout_width
is set to "wrap_content"
. Other layout_width
values override the ems width setting.
Adding an android:textSize
attribute determines the physical width of the view to the textSize * length of a text of n 'M's set above.
What is android:ems in android application design
The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion. Declarations such as 'text-indent: 1.5em' and 'margin: 1em' are extremely common in CSS.
em is basically CSS property for font sizes
android:ems or setEms(n) sets the width of a TextView to fit a text of n 'M' letters regardless of the actual text extension and text size. See wikipedia Em unit
but only when the layout_width is set to "wrap_content". Other layout_width values override the ems width setting.
Adding an android:textSize attribute determines the physical width of the view to the textSize * length of a text of n 'M's set above.
What is android:ems attribute in Edit Text?
Taken from: http://www.w3.org/Style/Examples/007/units:
The em is simply the font size. In an element with a 2in font, 1em
thus means 2in. Expressing sizes, such as margins and paddings, in em
means they are related to the font size, and if the user has a big
font (e.g., on a big screen) or a small font (e.g., on a handheld
device), the sizes will be in proportion. Declarations such as
'text-indent: 1.5em' and 'margin: 1em' are extremely common in CSS.
em
is basically CSS property for font sizes.
What can affect android:ems size?
Okay, I found the culprit. I thought that ems size x will be always the same for all characters. But I completely forgot that we have monospace and proportional fonts. And when we set ems to some x, it will be x*y where y is the width of the widest letter (usually M). But width of other letters will be smaller.
It is clear on this picture:
"M" letters is much wider then "1"!
Solution: we can simply switch to monospace font, like serif-monospace
:
android:ellipsize=end and android:maxEms not working
Both of your attributes for adding 'the three dots effect' are correct
android:ellipsize="end"
android:singleLine="true"
but the effect happens only when the TextView
does not have any free space on the screen to show the text.
To set the limit of the text in TextView
you can use
android:maxLength="8"
but it doesn't add the three dots, and as far as I am aware you would have to do it manually.
Something like this
String text = "A bit longer text";
if (text.length() > 8) {
text = text.substring(0, 8) + "...";
}
The android:maxEms
is something else than previous, you can read more about it
What is meant by Ems? (Android TextView)
Getting ems size of a string in Android
The following in the android dev references helped me:
https://developer.android.com/reference/android/widget/MultiAutoCompleteTextView.html
especially if you look at the documentation for the following:
void performFiltering (CharSequence text,
int start,
int end,
int keyCode)
Android TextView html added url not working
You are running into trouble using android:autoLink="all"
in your layout. I suggest that you delete that autolink line and adjust your code as follows:
stationSponsorUrl.setMovementMethod(LinkMovementMethod.getInstance());
String anchorText;
if (station.getSponsorUrl().length() > 32) {
anchorText = getString(R.string.www_link)
} else {
anchorText = station.getSponsorUrl()
}
stationSponsorUrl.setMovementMethod(LinkMovementMethod.getInstance());
stationSponsorUrl.setText(
HtmlCompat.fromHtml(
"<a href=\"" + station.getSponsorUrl() + "\">" + anchorText + "</a>\n", HtmlCompat.FROM_HTML_MODE_LEGACY
)
);
You could also turn autolink off for long URLs using setAutoLinkMask():
stationSponsorUrl.setAutoLinkMask(0)
Related Topics
Get Gps Location in a Broadcast Receiver/Or Service to Broadcast Receiver Data Transfer
Default Activity Not Found in Android Studio
Espresso - How to Check If an Activity Is Launched After Performing a Certain Action
Proguard Missing Type Parameter
Bitmap, Bitmap.Recycle(), Weakreferences, and Garbage Collection
Android Take Screenshot via Code
Android Crash When App Is Closed and Reopened
App Completely Restarting When Launched by Icon Press in Launcher
Android Action_Shutdown Broadcast Not Working
How to Get Documents in an Android Directory That Phonegap Will See
Android: Xml Layout for a Listview with Different Items