本文整理汇总了Java中android.widget.TextView.setMaxWidth方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setMaxWidth方法的具体用法?Java TextView.setMaxWidth怎么用?Java TextView.setMaxWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setMaxWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBadgeText
import android.widget.TextView; //导入方法依赖的package包/类
/**
* @param index of tab where badge should be added
* @param text the text of the badge (null to hide the badge)
*/
public void setBadgeText(int index, @Nullable String text) {
TabLayout.Tab tab = getTabAt(index);
if (tab == null || tab.getCustomView() == null) {
Log.e("BadgedTabLayout", "Tab is null. Not setting custom view");
return;
}
TextView badge = (TextView) tab.getCustomView().findViewById(R.id.textview_tab_badge);
TextView tabText = (TextView) tab.getCustomView().findViewById(R.id.textview_tab_title);
if (text == null) {
badge.setVisibility(View.GONE);
tabText.setMaxWidth(Integer.MAX_VALUE);
} else {
int maxWidth = getResources().getDimensionPixelSize(R.dimen.tab_text_max_width);
badge.setText(text);
tabText.setMaxWidth(maxWidth);
badge.setVisibility(View.VISIBLE);
}
TransitionManager.beginDelayedTransition((ViewGroup) tab.getCustomView());
}
示例2: ViewHolder
import android.widget.TextView; //导入方法依赖的package包/类
private ViewHolder() {
super(((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.list_item_message, null));
TextView nachricht = itemView.findViewById(R.id.nachricht);
nachricht.setMaxWidth(GraphicUtils.getDisplayWidth() * 2 / 3);
TextView absender = itemView.findViewById(R.id.absender);
absender.setMaxWidth(GraphicUtils.getDisplayWidth() * 2 / 3);
itemView.setOnLongClickListener(longClickListener);
itemView.setOnClickListener(clickListener);
}
示例3: update
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Updates the total and how it's broken down.
*
* @param cart The shopping cart contents and the total.
*/
public void update(ShoppingCart cart) {
Context context = mBreakdownLayout.getContext();
CharSequence totalPrice = createValueString(
cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true);
// Show the updated text view if the total changed.
showUpdateIfTextChanged(totalPrice);
// Update the summary to display information about the total.
setSummaryText(cart.getTotal().getLabel(), totalPrice);
mBreakdownLayout.removeAllViews();
if (cart.getContents() == null) return;
int maximumDescriptionWidthPx =
((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3;
// Update the breakdown, using one row per {@link LineItem}.
int numItems = cart.getContents().size();
mBreakdownLayout.setRowCount(numItems);
for (int i = 0; i < numItems; i++) {
LineItem item = cart.getContents().get(i);
TextView description = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending()
? R.style.PaymentsUiSectionPendingTextEndAligned
: R.style.PaymentsUiSectionDescriptiveTextEndAligned);
description.setText(item.getLabel());
description.setEllipsize(TruncateAt.END);
description.setMaxLines(2);
if (maximumDescriptionWidthPx > 0) {
description.setMaxWidth(maximumDescriptionWidthPx);
}
TextView amount = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending()
? R.style.PaymentsUiSectionPendingTextEndAligned
: R.style.PaymentsUiSectionDescriptiveTextEndAligned);
amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));
// Each item is represented by a row in the GridLayout.
GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(0, 1, GridLayout.END));
GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(1, 1, GridLayout.END));
ApiCompatibilityUtils.setMarginStart(amountParams,
context.getResources().getDimensionPixelSize(
R.dimen.payments_section_descriptive_item_spacing));
mBreakdownLayout.addView(description, descriptionParams);
mBreakdownLayout.addView(amount, amountParams);
}
}