本文整理匯總了Java中android.widget.TextView.getLineCount方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getLineCount方法的具體用法?Java TextView.getLineCount怎麽用?Java TextView.getLineCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getLineCount方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createPages
import android.widget.TextView; //導入方法依賴的package包/類
/**
* method that splits the document content in pages that fit the user's screen according to his settings preferences
* @param textView fragment textView
* @param content document content
* @param maxLines maxLines in a page
*/
private void createPages(String content, TextView textView, int maxLines){
boolean flag = true;
int start, end;
for (int i = 0; flag; i = i + maxLines) {
start = textView.getLayout().getLineStart(i);
if(textView.getLineCount() > i + maxLines - 1){
end = textView.getLayout().getLineEnd(i + maxLines - 1);
}
else{
flag = false;
end = textView.getLayout().getLineEnd(textView.getLineCount() - 1);
}
String str;
if(flag) str = content.substring(start, end);
else str = content.substring(start);
pages.add(str);
pageStart.add(start);
}
}
示例2: onClickCard
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public void onClickCard(View v, Update update) {
// if card is clicked and the line count is bigger than 3 (meaning it can be expanded/"dexpanded")
TextView tvText = v.findViewById(R.id.tv_updatecard_text);
View viewExpand = v.findViewById(R.id.view_updatecard_expand);
if (tvText.getLineCount() > 3) {
// if current max lines is 3, expand to 100 lines, and else "dexpand" back to 3
// it uses TextViewCompat instead of the given method for API 15 compatibility
if (TextViewCompat.getMaxLines(tvText) == 3) {
tvText.setMaxLines(100);
viewExpand.setBackgroundResource(R.drawable.ic_arrow_drop_up_grey_600_24dp);
} else {
tvText.setMaxLines(3);
viewExpand.setBackgroundResource(R.drawable.ic_arrow_drop_down_grey_600_24dp);
}
}
}
示例3: measureTextViewHeight
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 獲取文本實際所占高度,輔助用於計算行高,行數
*
* @param text 文本
* @param textSize 字體大小
* @param deviceWidth 屏幕寬度
*/
private void measureTextViewHeight(String text, float textSize, int deviceWidth) {
TextView textView = new TextView(getContext());
textView.setText(text);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
originalLineCount = textView.getLineCount();
originalHeight = textView.getMeasuredHeight();
}