gpt4 book ai didi

android - 如何识别textview到达屏幕底部?

转载 作者:行者123 更新时间:2023-11-30 03:00:28 25 4
gpt4 key购买 nike

我正在开发图书阅读器应用程序。我有 LinearLayout。

<LinearLayout
android:id="@+id/llReader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical" >
</LinearLayout>

我正在逐行从内部存储中获取 html 文件。我正在为一行分配一个 TextView 并将它们放入 LinearLayout。

private void readFile(LinearLayout ll) throws IOException {

fileName = myDatabase.getBookById(book_id) + ".html";

FileInputStream fis = openFileInput(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));

String line = "";

while (null != (line = br.readLine())) {

TextView tv = new TextView(this);
tv.setTextSize(24);
tv.setText(Html.fromHtml(line));
ll.addView(tv);
}
br.close();
}

如何识别 TextViews 到达屏幕底部?

最佳答案

您可以通过像素操作:

    private void readFile(LinearLayout ll) throws IOException {

fileName = myDatabase.getBookById(book_id) + ".html";

FileInputStream fis = openFileInput(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));

String line = "";

int parentHeight = ll.getHeight(); // in pixels
int sumHeigth = 0;

while (null != (line = br.readLine())) {

TextView tv = new TextView(this);
tv.setTextSize(24);
tv.setText(Html.fromHtml(line));
ll.addView(tv);
sumHeigth += tv.getHeight();
if(sumHeigth>parentHeight) {
// if can't fit in LinearLayout
ll.removeView(tv);
// break; // or what you want in this situation
}
}
br.close();
}

关于android - 如何识别textview到达屏幕底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22622032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com