2017-06-20 68 views
4

我正在尝试构建一本书阅读器。而现在我有一个很长的文本,填满了整个屏幕,甚至一些文本没有了屏幕。我想知道如何找到在屏幕上完全可见的最后一个字母,这样我就可以将文本分成页面。Android:如何确定TextView中最后一个完全可见的字母?

例如,所有的行之前

“坏消息,弗农,”她说......

完全可见的文本,其余文本必须移动到另一页。

enter image description here

这样的(另一个文本页面与 “坏消息” 开始)

enter image description here

这里是我以前在例如

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="10dp"> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:text="...some text..." /> 
</RelativeLayout> 
+1

你正在努力实现页面夹板 请检查了这一点 https://stackoverflow.com/questions/20204348/how-to-break-styled-text-into-pages-in-android – argando

+0

我曾尝试示例应用程序从argando的链接提供,它似乎工作为我想要 – Season

回答

1

我上面的布局认为预测文本将要结束的地方将是困难/不可能的,除非你使用了等宽字体,例如信使。但是不要采取这种方法,我可以建议的另一种方法是简单地为图书阅读器的每个页面提供不变数量的字符。是的,这意味着如果使用非等宽字体,则不会知道要呈现的确切行数。但是,占用的线数应该在相当窄的范围内,并且很可能不会被用户察觉。

您可以在这里使用ScrollView,其中包含实际的TextView,其中包含每个页面的文本。这里是什么,可能看起来像一个骨架:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="10dp"> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="...some text..." /> 
    </ScrollView> 
</RelativeLayout> 

使用ScrollView,用户可以然后只需上下拖动赶上这可能不适合到单个屏幕的任何内容。再次,这使您不必担心提供确切数量的内容。

+0

我知道使用ScrollView与TextView是一种简单的方法来显示长文本,但它仍然不是一个分页方法 – Season

+0

@Season我说的是使用一个滚动视图,然后你不必担心“页面分割”。大多数读者可能会遵循这种方法 –

相关问题