gpt4 book ai didi

android - 将长字符串分成多页

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

<分区>

我试图在多个页面中显示一个长字符串。我的 Activity.xml 有一个占据屏幕高度 90% 的 TextView (这是我设置了相对布局的方式)。我需要一些帮助来找出可以用来实现我的目标的正确方法/类

下面是我的代码。加粗的内容(代码中以**开头的注释)是我需要帮助的地方。

public class StoryActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story);

String contentString;
String pageString;
final int screenWidth;
final int screenHeight;
final int pageWidth;
final int pageHeight;
final int totalPages;
int pageNumber;


//load the content into the string contentString
InputStream is = getAssets().open("Story.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
contentString = new String(buffer);

// get screen dimensions
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels;
screenHeight= dm.heightPixels;

// create textview
TextView tv = (TextView)findViewById(R.id.textViewStory);

// calculate pageheight since textview size is 90% of the screen
pageHeight = (int) (0.9* screenHeight);
pageWidth = screenWidth;

**// 1)need to find number of lines which will fit pageHeight
// 2)then I need to find total number of lines in my String contentString
// 3)dividing 2) by 1) can give me number of pages required to display
// contentString.
// 4)I can then concatenate contentString at number of lines as found in
// 1) and thus I know what text (pageString) to display in page1**

tv.setText(pageString);

**// steps 4) can be repeated to display next page when user click
// “nextpage” button**

}

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