如何獲取 TextView 中輸入行的最大數?
DisplayMetrics metrics = new DisplayMetrics ();
getWindowManager (). getDefaultDisplay (). getMetrics (metrics);
float width = metrics.widthPixels;
float height = metrics.heightPixels;
int lines = (int) (height / textView.getLineHeight ());
System.out.println (lines);
TextView tv1 = (TextView) findViewById(R.id.tv1);
tv1.setText("abcd\nhello\nworld123\n333333");
tv1.post(new Runnable() {
@Override
public void run() {
int lineCount = tv1.getLineCount();
Toast.makeText(MainActivity.this, "行數為:"+lineCount, Toast.LENGTH_LONG).show();
}//行數為4
});
這樣也可以獲取~