本文整理汇总了Java中android.support.v4.widget.TextViewCompat.getMaxLines方法的典型用法代码示例。如果您正苦于以下问题:Java TextViewCompat.getMaxLines方法的具体用法?Java TextViewCompat.getMaxLines怎么用?Java TextViewCompat.getMaxLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.widget.TextViewCompat
的用法示例。
在下文中一共展示了TextViewCompat.getMaxLines方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClickCard
import android.support.v4.widget.TextViewCompat; //导入方法依赖的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);
}
}
}
示例2: determineNumberOfValidGroupLines
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
public static boolean determineNumberOfValidGroupLines(FormEntryActivity activity,
Rect newRootViewDimensions,
boolean hasGroupLabel,
boolean shouldHideGroupLabel) {
FrameLayout header = (FrameLayout)activity.findViewById(R.id.form_entry_header);
TextView groupLabel = ((TextView)header.findViewById(R.id.form_entry_group_label));
int numberOfGroupLinesAllowed =
getNumberOfGroupLinesAllowed(groupLabel, newRootViewDimensions, activity);
if (TextViewCompat.getMaxLines(groupLabel) != numberOfGroupLinesAllowed) {
shouldHideGroupLabel = numberOfGroupLinesAllowed == 0;
groupLabel.setMaxLines(numberOfGroupLinesAllowed);
updateGroupViewVisibility(header, groupLabel, hasGroupLabel, shouldHideGroupLabel);
}
return shouldHideGroupLabel;
}
示例3: onMeasure
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
public void onMeasure(int origWidthMeasureSpec, int origHeightMeasureSpec) {
int widthMeasureSpec;
int specWidthSize = MeasureSpec.getSize(origWidthMeasureSpec);
int specWidthMode = MeasureSpec.getMode(origWidthMeasureSpec);
int maxWidth = TabLayout.this.getTabMaxWidth();
int heightMeasureSpec = origHeightMeasureSpec;
if (maxWidth <= 0 || (specWidthMode != 0 && specWidthSize <= maxWidth)) {
widthMeasureSpec = origWidthMeasureSpec;
} else {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(TabLayout.this.mTabMaxWidth, Integer.MIN_VALUE);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (this.mTextView != null) {
Resources res = getResources();
float textSize = TabLayout.this.mTabTextSize;
int maxLines = this.mDefaultMaxLines;
if (this.mIconView != null && this.mIconView.getVisibility() == 0) {
maxLines = 1;
} else if (this.mTextView != null && this.mTextView.getLineCount() > 1) {
textSize = TabLayout.this.mTabTextMultiLineSize;
}
float curTextSize = this.mTextView.getTextSize();
int curLineCount = this.mTextView.getLineCount();
int curMaxLines = TextViewCompat.getMaxLines(this.mTextView);
if (textSize != curTextSize || (curMaxLines >= 0 && maxLines != curMaxLines)) {
boolean updateTextView = true;
if (TabLayout.this.mMode == 1 && textSize > curTextSize && curLineCount == 1) {
Layout layout = this.mTextView.getLayout();
if (layout == null || approximateLineWidth(layout, 0, textSize) > ((float) layout.getWidth())) {
updateTextView = false;
}
}
if (updateTextView) {
this.mTextView.setTextSize(0, textSize);
this.mTextView.setMaxLines(maxLines);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
}
示例4: onMeasure
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
@Override
public void onMeasure(final int origWidthMeasureSpec, final int origHeightMeasureSpec) {
final int specWidthSize = MeasureSpec.getSize(origWidthMeasureSpec);
final int specWidthMode = MeasureSpec.getMode(origWidthMeasureSpec);
final int maxWidth = getTabMaxWidth();
final int widthMeasureSpec;
final int heightMeasureSpec = origHeightMeasureSpec;
if (maxWidth > 0 && (specWidthMode == MeasureSpec.UNSPECIFIED
|| specWidthSize > maxWidth)) {
// If we have a max width and a given spec which is either unspecified or
// larger than the max width, update the width spec using the same mode
widthMeasureSpec = MeasureSpec.makeMeasureSpec(mTabMaxWidth, MeasureSpec.AT_MOST);
} else {
// Else, use the original width spec
widthMeasureSpec = origWidthMeasureSpec;
}
// Now lets measure
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// We need to switch the text size based on whether the text is spanning 2 lines or not
if (mTextView != null) {
final Resources res = getResources();
float textSize = mTabTextSize;
int maxLines = mDefaultMaxLines;
if (mIconView != null && mIconView.getVisibility() == VISIBLE) {
// If the icon view is being displayed, we limit the text to 1 line
maxLines = 1;
} else if (mTextView != null && mTextView.getLineCount() > 1) {
// Otherwise when we have text which wraps we reduce the text size
textSize = mTabTextMultiLineSize;
}
final float curTextSize = mTextView.getTextSize();
final int curLineCount = mTextView.getLineCount();
final int curMaxLines = TextViewCompat.getMaxLines(mTextView);
if (textSize != curTextSize || (curMaxLines >= 0 && maxLines != curMaxLines)) {
// We've got a new text size and/or max lines...
boolean updateTextView = true;
if (mMode == MODE_FIXED && textSize > curTextSize && curLineCount == 1) {
// If we're in fixed mode, going up in text size and currently have 1 line
// then it's very easy to get into an infinite recursion.
// To combat that we check to see if the change in text size
// will cause a line count change. If so, abort the size change and stick
// to the smaller size.
final Layout layout = mTextView.getLayout();
if (layout == null || approximateLineWidth(layout, 0, textSize)
> getMeasuredWidth() - getPaddingLeft() - getPaddingRight()) {
updateTextView = false;
}
}
if (updateTextView) {
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
mTextView.setMaxLines(maxLines);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
}
示例5: update
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
final void update() {
final Tab tab = mTab;
final View custom = tab != null ? tab.getCustomView() : null;
if (custom != null) {
final ViewParent customParent = custom.getParent();
if (customParent != this) {
if (customParent != null) {
((ViewGroup) customParent).removeView(custom);
}
addView(custom);
}
mCustomView = custom;
if (mTextView != null) {
mTextView.setVisibility(GONE);
}
if (mIconView != null) {
mIconView.setVisibility(GONE);
mIconView.setImageDrawable(null);
}
mCustomTextView = (TextView) custom.findViewById(android.R.id.text1);
if (mCustomTextView != null) {
mDefaultMaxLines = TextViewCompat.getMaxLines(mCustomTextView);
}
mCustomIconView = (ImageView) custom.findViewById(android.R.id.icon);
} else {
// We do not have a custom view. Remove one if it already exists
if (mCustomView != null) {
removeView(mCustomView);
mCustomView = null;
}
mCustomTextView = null;
mCustomIconView = null;
}
if (mCustomView == null) {
// If there isn't a custom view, we'll us our own in-built layouts
if (mIconView == null) {
ImageView iconView = (ImageView) LayoutInflater.from(getContext())
.inflate(R.layout.design_layout_tab_icon, this, false);
addView(iconView, 0);
mIconView = iconView;
}
if (mTextView == null) {
TextView textView = (TextView) LayoutInflater.from(getContext())
.inflate(R.layout.design_layout_tab_text, this, false);
addView(textView);
mTextView = textView;
mDefaultMaxLines = TextViewCompat.getMaxLines(mTextView);
}
TextViewCompat.setTextAppearance(mTextView, mTabTextAppearance);
if (mTabTextColors != null) {
mTextView.setTextColor(mTabTextColors);
}
updateTextAndIcon(mTextView, mIconView);
} else {
// Else, we'll see if there is a TextView or ImageView present and update them
if (mCustomTextView != null || mCustomIconView != null) {
updateTextAndIcon(mCustomTextView, mCustomIconView);
}
}
// Finally update our selected state
setSelected(tab != null && tab.isSelected());
}
示例6: update
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
final void update() {
View custom;
Tab tab = this.mTab;
if (tab != null) {
custom = tab.getCustomView();
} else {
custom = null;
}
if (custom != null) {
TabView customParent = custom.getParent();
if (customParent != this) {
if (customParent != null) {
customParent.removeView(custom);
}
addView(custom);
}
this.mCustomView = custom;
if (this.mTextView != null) {
this.mTextView.setVisibility(8);
}
if (this.mIconView != null) {
this.mIconView.setVisibility(8);
this.mIconView.setImageDrawable(null);
}
this.mCustomTextView = (TextView) custom.findViewById(16908308);
if (this.mCustomTextView != null) {
this.mDefaultMaxLines = TextViewCompat.getMaxLines(this.mCustomTextView);
}
this.mCustomIconView = (ImageView) custom.findViewById(16908294);
} else {
if (this.mCustomView != null) {
removeView(this.mCustomView);
this.mCustomView = null;
}
this.mCustomTextView = null;
this.mCustomIconView = null;
}
if (this.mCustomView == null) {
if (this.mIconView == null) {
ImageView iconView = (ImageView) LayoutInflater.from(getContext()).inflate(R.layout.design_layout_tab_icon, this, false);
addView(iconView, 0);
this.mIconView = iconView;
}
if (this.mTextView == null) {
TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.design_layout_tab_text, this, false);
addView(textView);
this.mTextView = textView;
this.mDefaultMaxLines = TextViewCompat.getMaxLines(this.mTextView);
}
this.mTextView.setTextAppearance(getContext(), TabLayout.this.mTabTextAppearance);
if (TabLayout.this.mTabTextColors != null) {
this.mTextView.setTextColor(TabLayout.this.mTabTextColors);
}
updateTextAndIcon(this.mTextView, this.mIconView);
} else if (this.mCustomTextView != null || this.mCustomIconView != null) {
updateTextAndIcon(this.mCustomTextView, this.mCustomIconView);
}
}
示例7: onMeasure
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
@Override
public void onMeasure(final int origWidthMeasureSpec, final int origHeightMeasureSpec) {
final int specWidthSize = MeasureSpec.getSize(origWidthMeasureSpec);
final int specWidthMode = MeasureSpec.getMode(origWidthMeasureSpec);
final int maxWidth = getTabMaxWidth();
final int widthMeasureSpec;
final int heightMeasureSpec = origHeightMeasureSpec;
if (maxWidth > 0 && (specWidthMode == MeasureSpec.UNSPECIFIED || specWidthSize > maxWidth)) {
// If we have a max width and a given spec which is either unspecified or
// larger than the max width, update the width spec using the same mode
widthMeasureSpec = MeasureSpec.makeMeasureSpec(tabMaxWidth, MeasureSpec.AT_MOST);
} else {
// Else, use the original width spec
widthMeasureSpec = origWidthMeasureSpec;
}
// Now lets measure
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// We need to switch the text size based on whether the text is spanning 2 lines or not
if (textView != null) {
float textSize = tabTextSize;
int maxLines = defaultMaxLines;
if (iconView != null && iconView.getVisibility() == VISIBLE) {
// If the icon view is being displayed, we limit the text to 1 line
maxLines = 1;
} else if (textView != null && textView.getLineCount() > 1) {
// Otherwise when we have text which wraps we reduce the text size
textSize = tabTextMultiLineSize;
}
final float curTextSize = textView.getTextSize();
final int curLineCount = textView.getLineCount();
final int curMaxLines = TextViewCompat.getMaxLines(textView);
if (textSize != curTextSize || (curMaxLines >= 0 && maxLines != curMaxLines)) {
// We've got a new text size and/or max lines...
boolean updateTextView = true;
if (mode == MODE_FIXED && textSize > curTextSize && curLineCount == 1) {
// If we're in fixed mode, going up in text size and currently have 1 line
// then it's very easy to get into an infinite recursion.
// To combat that we check to see if the change in text size
// will cause a line count change. If so, abort the size change and stick
// to the smaller size.
final Layout layout = textView.getLayout();
if (layout == null
|| approximateLineWidth(layout, 0, textSize)
> getMeasuredWidth() - getPaddingLeft() - getPaddingRight()) {
updateTextView = false;
}
}
if (updateTextView) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
textView.setMaxLines(maxLines);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
}
示例8: onMeasure
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
@Override
public void onMeasure(final int origWidthMeasureSpec, final int origHeightMeasureSpec) {
final int specWidthSize = MeasureSpec.getSize(origWidthMeasureSpec);
final int specWidthMode = MeasureSpec.getMode(origWidthMeasureSpec);
final int maxWidth = getTabMaxWidth();
final int widthMeasureSpec;
final int heightMeasureSpec = origHeightMeasureSpec;
if (maxWidth > 0 && (specWidthMode == MeasureSpec.UNSPECIFIED || specWidthSize > maxWidth)) {
// If we have a max width and a given spec which is either unspecified or
// larger than the max width, update the width spec using the same mode
widthMeasureSpec = MeasureSpec.makeMeasureSpec(mTabMaxWidth, MeasureSpec.AT_MOST);
} else {
// Else, use the original width spec
widthMeasureSpec = origWidthMeasureSpec;
}
// Now lets measure
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// We need to switch the text size based on whether the text is spanning 2 lines or not
if (mTextView != null) {
final Resources res = getResources();
float textSize = mTabTextSize;
int maxLines = mDefaultMaxLines;
if (mIconView != null && mIconView.getVisibility() == VISIBLE) {
// If the icon view is being displayed, we limit the text to 1 line
maxLines = 1;
} else if (mTextView != null && mTextView.getLineCount() > 1) {
// Otherwise when we have text which wraps we reduce the text size
textSize = mTabTextMultiLineSize;
}
final float curTextSize = mTextView.getTextSize();
final int curLineCount = mTextView.getLineCount();
final int curMaxLines = TextViewCompat.getMaxLines(mTextView);
if (textSize != curTextSize || (curMaxLines >= 0 && maxLines != curMaxLines)) {
// We've got a new text size and/or max lines...
boolean updateTextView = true;
if (mMode == MODE_FIXED && textSize > curTextSize && curLineCount == 1) {
// If we're in fixed mode, going up in text size and currently have 1 line
// then it's very easy to get into an infinite recursion.
// To combat that we check to see if the change in text size
// will cause a line count change. If so, abort the size change and stick
// to the smaller size.
final Layout layout = mTextView.getLayout();
if (layout == null
|| approximateLineWidth(layout, 0, textSize)
> getMeasuredWidth() - getPaddingLeft() - getPaddingRight()) {
updateTextView = false;
}
}
if (updateTextView) {
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
mTextView.setMaxLines(maxLines);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
}
示例9: update
import android.support.v4.widget.TextViewCompat; //导入方法依赖的package包/类
final void update() {
final Tab tab = mTab;
final View custom = tab != null ? tab.getCustomView() : null;
if (custom != null) {
final ViewParent customParent = custom.getParent();
if (customParent != this) {
if (customParent != null) {
((ViewGroup) customParent).removeView(custom);
}
addView(custom);
}
mCustomView = custom;
if (mTextView != null) {
mTextView.setVisibility(GONE);
}
if (mIconView != null) {
mIconView.setVisibility(GONE);
mIconView.setImageDrawable(null);
}
mCustomTextView = (TextView) custom.findViewById(android.R.id.text1);
if (mCustomTextView != null) {
mDefaultMaxLines = TextViewCompat.getMaxLines(mCustomTextView);
}
mCustomIconView = (ImageView) custom.findViewById(android.R.id.icon);
} else {
// We do not have a custom view. Remove one if it already exists
if (mCustomView != null) {
removeView(mCustomView);
mCustomView = null;
}
mCustomTextView = null;
mCustomIconView = null;
}
if (mCustomView == null) {
// If there isn't a custom view, we'll us our own in-built layouts
if (mIconView == null) {
ImageView iconView =
(ImageView)
LayoutInflater.from(getContext())
.inflate(R.layout.design_layout_tab_icon, this, false);
addView(iconView, 0);
mIconView = iconView;
}
if (mTextView == null) {
TextView textView =
(TextView)
LayoutInflater.from(getContext())
.inflate(R.layout.design_layout_tab_text, this, false);
addView(textView);
mTextView = textView;
mDefaultMaxLines = TextViewCompat.getMaxLines(mTextView);
}
TextViewCompat.setTextAppearance(mTextView, mTabTextAppearance);
if (mTabTextColors != null) {
mTextView.setTextColor(mTabTextColors);
}
updateTextAndIcon(mTextView, mIconView);
} else {
// Else, we'll see if there is a TextView or ImageView present and update them
if (mCustomTextView != null || mCustomIconView != null) {
updateTextAndIcon(mCustomTextView, mCustomIconView);
}
}
// Finally update our selected state
setSelected(tab != null && tab.isSelected());
}