Java Code Examples for android.widget.TextView.setMaxWidth()

The following are Jave code examples for showing how to use setMaxWidth() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: badgedtablayout   File: BadgedTabLayout.java   View Source Code Vote up 6 votes
/**
 * @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());
}
 
Example 2
Project: leoapp-sources   File: MessageAdapter.java   View Source Code Vote up 5 votes
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);
}
 
Example 3
Project: chromium-for-android-56-debug-video   File: PaymentRequestSection.java   View Source Code Vote up 4 votes
/**
 * 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);
    }
}