NIKUNJ GADHIYA
NIKUNJ GADHIYA

Reputation: 103

create book reader in android using simple text

I need your knowledge I have to create book reader applications like the amazon kindle but, using simple text formate not any file formate like pdf, epub or any. Load simple text in textview.

I have one idea, assume we have 1000 lines in one book. Load this text in textview with android:layout_height="match_parent". when text crosses the limit of texview hight, it auto load remaining text in the next textview but, how to know the text crosses the limit (eclipsing) of textview.

To implement this I have written this code but l.getEllipsisCount(lines - 1) return 0.

lLayout.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
        override fun onGlobalLayout() {
            // your code here. `this` should work
            val l = tvHtml.getLayout();
            if (l != null) {
                var lines = l.getLineCount()
                if (lines > 0) {
                    if (l.getEllipsisCount(lines - 1) > 0) {//2147483647
                        Log.d("log ---------", "Text is ellipsized")
                    }
                }
            }
        }
    })

This is my logic but, if you have any new ideas to perform this task, pls inform me.

Thanks

Upvotes: 1

Views: 362

Answers (0)

Related Questions