I am making a text editor for Android and I would like to show the number of every line in the EditText
.
My solution was to make a TextView
with lines numbers and place an EditText
next to TextView
. Like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:fillViewport="true">
<TextView
android:id="@+id/lines_numbering_view"
android:layout_width="wrap_content"
android:minWidth="10dp"
android:layout_height="match_parent"
android:textSize="18sp"
android:text="1\n"/>
<EditText
<!--EditText options here-->
/>
</LinearLayout>
This works fine but there is one fact... If the lines count is about 600, when TextView's
onMeasure
method is called, it makes the app to freeze for a 0.5 seconds.
So, what can I do to improve the performance of TextView or are there any good solutions of numbering lines?
The line number view can be seen and implemented as a ruler. All it needs as input is the line height. From there it can display increasing line numbers at the proper vertical positions. It need not know the number of lines in the content view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.