本文整理汇总了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();
}