[JAVA] How to implement one-line display of TextView in Android development

Controlling single-line display in TextView

In iOS, it is a line display of Android TextView, which is equivalent to UILabel. I was surprised today so I will share it. The premise is that after getting the character string to be displayed in Text by API communication, let UIKit setText and make it Label or TextView. It is a situation to display characters. If it's a fixed string, it can't be a story of such control!

About UI Label on iOS

By default, UILabel has two or more lines, but if the height of UILabel is a size that can display only one line, "1 line" is displayed as a character string, and the character breaks are abbreviated as "xxxx ...".

About TextView on Android

By default, if the number of characters is 2 or more lines, the TextView will be displayed. What was displayed as a character string was "1 line", and the part where the character was cut off was displayed as "xxxx".

So the dictator asked me to match the iOS specifications. It was the agenda this time to display "..." in the program.

About implementation method

label_text.xml


<TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:singleLine="true"
        android:textColor="@drawable/RED" />

Set ʻandroid: singleLinetotrue and By setting ʻeandroid: ellipsize to ʻend`, "xxxx ..." could be realized.

About ellipsize options

The ellipsize options are controlled as shown in the table below.

Value TextView default value motion
none do nothing
start ...xxxx
middle xxx...xxx
end xxxxxx...

At the development site of smartphone apps, most of the specifications are for iOS or Android, so You can realize a smart implementation by knowing in advance how the behavior changes between both OSs.

With that in mind, I'm currently studying Android SDK and UI.

Well, but I want to touch Kotlin soon.

Recommended Posts

How to implement one-line display of TextView in Android development
[Android application development] How to display in full screen (notification bar hidden)
Android development, how to check null in the value of JSON object
[Rails, JS] How to implement asynchronous display of comments
Summary of how to implement default arguments in Java
[Behavior confirmed in December 2020] How to implement the alert display function
How to implement search functionality in Rails
How to implement date calculation in Java
How to implement Kalman filter in Java
How to implement coding conventions in Java
How to implement ranking functionality in Rails
How to implement asynchronous processing in Outsystems
How to use ExpandableListView in Android Studio
How to display error messages in Japanese
How to execute with commands of normal development language in Docker development environment
Summary of how to select elements in Selenium
How to display a web page in Java
[Android] Implement a function to display passwords quickly
How to use JQuery in js.erb of Rails6
How to display the result of form input
How to implement optimistic locking in REST API
How to implement Pagination in GraphQL (for ruby)
Summarize the life cycle of Java objects to be aware of in Android development
How to implement UICollectionView in Swift with code only
[Android Studio] How to change TextView to any font [Java]
How to set the display time to Japan time in Rails
How to implement guest login in 5 minutes in rails portfolio
How to implement a like feature in Ajax in Rails
How to display a browser preview in VS Code
How to use CommandLineRunner in Spring Batch of Spring Boot
[Android] How to get the setting language of the terminal
How to prevent editTextPreference of android PreferenceFragmentCompat from breaking
[Rails] How to display an image in the view
How to use UsageStatsManager in Android Studio (How to check the startup time of other apps)
[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
How to display the select field of time_select every 30 minutes
Introduction to Android application development
How to get values in real time with TextWatcher (Android)
[Java] How to display Wingdings
How to display a graph in Ruby on Rails (LazyHighChart)
[Android] Implement Adblock in WebView
[Rails] How to display the list of posts by category
How to derive the last day of the month in Java
[Rails] How to implement scraping
[Java] How to implement multithreading
How to change BackgroundColor etc. of NavigationBar in Swift UI
[Rails] How to display information stored in the database in view
[Android] Try to display the effect on the touched part of the screen, which is common in games.
I tried to implement Ajax processing of like function in Rails
[Sprint Boot] How to use 3 types of SqlParameterSource defined in org.springframework.jdbc.core.namedparam
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
[rails] How to display parent information in child view in nested relationships
How to implement a job that uses Java API in JobScheduler
How to display 0 on the left side of the standard input value
[Rails] How to omit the display of the character string of the link_to method
Source to display character array with numberPicker in Android studio (Java)
How to delete large amounts of data in Rails and concerns
How to get the id of PRIMAY KEY auto_incremented in MyBatis
Only this! How to prevent forgetting code format in team development
How to output a list of strings in JSF as comma-separated strings