Example usage for android.widget TextView setMinWidth

List of usage examples for android.widget TextView setMinWidth

Introduction

In this page you can find the example usage for android.widget TextView setMinWidth.

Prototype

@android.view.RemotableViewMethod
public void setMinWidth(int minPixels) 

Source Link

Document

Sets the width of the TextView to be at least minPixels wide.

Usage

From source file:com.amazonaws.demo.messageboard.MessageQueueAdapter.java

public View getView(int pos, View convertView, ViewGroup parent) {
    TextView messageText = new TextView(parent.getContext());
    messageText.setText(this.getMessageText(pos));
    messageText.setGravity(Gravity.LEFT);
    messageText.setPadding(10, 10, 10, 10);
    messageText.setMaxWidth(200);/*from  www .j a v  a  2 s.c  o m*/
    messageText.setMinWidth(200);
    messageText.setTextSize(16);

    return messageText;
}

From source file:com.simplecity.amp_library.ui.views.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from   w w w.  jav a 2s .c om*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setTypeface(TypefaceManager.getInstance().getTypeface(TypefaceManager.SANS_SERIF_MEDIUM));
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setMinWidth(ResourceUtils.toPixels(72));
    textView.setSingleLine(true);

    // If we're running on Honeycomb or newer, then we can use the Theme's
    // selectableItemBackground to ensure that the View has a pressed state
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.list_selector, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);

    // Enable all-caps to match the Action Bar tab style
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.sumavision.talktv2.ui.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    // if (redTipPos == position) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.custom_tab_view, null);
    TextView tab = (TextView) view.findViewById(R.id.tab_text);
    tab.setText(title);//  w w  w .  j a  v  a  2  s.c  o m
    tab.setSingleLine();
    tab.setMinWidth(screenWidth / 8);
    redTip = (CircleImageView) view.findViewById(R.id.tab_tip);
    if (redTipPos == position) {
        redTip.setVisibility(View.VISIBLE);
    } else {
        redTip.setVisibility(View.GONE);
    }
    addTab(position, view);

    // } else {
    // TextView tab = new TextView(getContext());
    // tab.setGravity(Gravity.CENTER);
    // tab.setSingleLine();
    // tab.setText(title);
    // addTab(position, tab);
    // }
}

From source file:org.nla.tarotdroid.lib.ui.GameSetSynthesisFragment.java

/**
  * Refreshes the stats rows on the synthesis view.
  *//*from  w ww .jav a  2s  .  c  o m*/
protected void refreshPlayerStatsRows() {
    // sort players
    List<Player> sortedPlayers = this.getGameSet().getPlayers().getPlayers();
    Collections.sort(sortedPlayers, new PlayerScoreComparator());

    // get general data sources
    IGameSetStatisticsComputer gameSetStatisticsComputer = GameSetStatisticsComputerFactory
            .GetGameSetStatisticsComputer(this.getGameSet(), "guava");
    MapPlayersScores lastScores = this.getGameSet().getGameSetScores().getResultsAtLastGame();
    Map<Player, Integer> leadingCount = gameSetStatisticsComputer.getLeadingCount();
    Map<Player, Integer> leadingSuccesses = gameSetStatisticsComputer.getLeadingSuccessCount();
    Map<Player, Integer> calledCount = gameSetStatisticsComputer.getCalledCount();
    int minScoreEver = gameSetStatisticsComputer.getMinScoreEver();
    int maxScoreEver = gameSetStatisticsComputer.getMaxScoreEver();

    // format statistics lines
    for (int rank = 0; rank < sortedPlayers.size(); ++rank) {
        // get player specific data sources
        Player player = sortedPlayers.get(rank);
        int lastScore = lastScores == null ? 0 : lastScores.get(player);
        int successfulLeadingGamesCount = leadingSuccesses.get(player) == null ? 0
                : leadingSuccesses.get(player).intValue();
        int leadingGamesCount = leadingCount.get(player) == null ? 0 : leadingCount.get(player);
        int successRate = (int) (((double) successfulLeadingGamesCount) / ((double) leadingGamesCount) * 100.0);
        int minScoreForPlayer = gameSetStatisticsComputer.getMinScoreEverForPlayer(player);
        int maxScoreForPlayer = gameSetStatisticsComputer.getMaxScoreEverForPlayer(player);

        // get line widgets
        LinearLayout statRow = this.statsRows.get(rank + 1);
        //TextView statPlayerName = (TextView)statRow.findViewById(R.id.statPlayerName);
        TextView statScore = (TextView) statRow.findViewById(R.id.statScore);
        TextView statLeadingGamesCount = (TextView) statRow.findViewById(R.id.statLeadingGamesCount);
        TextView statSuccessfulGamesCount = (TextView) statRow.findViewById(R.id.statSuccessfulGamesCount);
        TextView statMinScore = (TextView) statRow.findViewById(R.id.statMinScore);
        TextView statMaxScore = (TextView) statRow.findViewById(R.id.statMaxScore);

        //          Bitmap playerImage = null;
        //          if (player.getPictureUri() != null && !player.getPictureUri().equals("")) {
        //             playerImage = UIHelper.getPlayerImage(this.getActivity(), player);
        //          }
        //          
        //            
        //            // assign values to widgets
        //            if (player.getFacebookId() != null) {
        //             // player facebook image
        //             ProfilePictureView pictureView = new ProfilePictureView(this.getActivity());
        //             pictureView.setProfileId(player.getFacebookId());
        //             pictureView.setPresetSize(ProfilePictureView.SMALL);
        //             //pictureView.setOnClickListener(playerClickListener);
        //             pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);
        //             statRow.removeViewAt(0);
        //               statRow.addView(pictureView, 0);
        //            }
        //            else {
        //               // WARNING: The properties below reference the style ScoreTextStyle, but we can't set a style at runtime.
        //               TextView playerName = new TextView(this.getActivity());
        //               playerName.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1));
        //               playerName.setGravity(Gravity.CENTER);
        //               playerName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        //               playerName.setEllipsize(TruncateAt.END);
        //               playerName.setSingleLine();
        //               playerName.setTextColor(Color.WHITE);
        //               playerName.setTypeface(null, Typeface.BOLD);
        //               playerName.setText(player.getName());
        //               //playerName.setBackgroundResource(R.drawable.border_player_white);
        //               statRow.removeViewAt(0);
        //               statRow.addView(playerName, 0);
        //            }

        OnClickListener playerClickListener = new PlayerClickListener(player);

        // facebook picture
        if (player.getFacebookId() != null) {
            ProfilePictureView pictureView = new ProfilePictureView(this.getActivity());
            pictureView.setProfileId(player.getFacebookId());
            pictureView.setPresetSize(ProfilePictureView.SMALL);
            pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);

            pictureView.setOnClickListener(playerClickListener);
            //this.addView(pictureView);
            statRow.removeViewAt(0);
            statRow.addView(pictureView, 0);
        }

        // contact picture
        else if (player.getPictureUri() != null
                && player.getPictureUri().toString().contains("content://com.android.contacts/contacts")) {
            Bitmap playerImage = UIHelper.getContactPicture(this.getActivity(),
                    Uri.parse(player.getPictureUri()).getLastPathSegment());
            ImageView imgPlayer = new ImageView(this.getActivity());
            imgPlayer.setImageBitmap(playerImage);
            imgPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);

            imgPlayer.setOnClickListener(playerClickListener);
            //this.addView(imgPlayer);
            statRow.removeViewAt(0);
            statRow.addView(imgPlayer, 0);
        }

        // no picture, only name
        else {
            TextView txtPlayer = new TextView(this.getActivity());
            txtPlayer.setText(player.getName());
            txtPlayer.setGravity(Gravity.CENTER);
            txtPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS);
            txtPlayer.setMinWidth(UIConstants.PLAYER_VIEW_WIDTH);
            txtPlayer.setHeight(UIConstants.PLAYER_VIEW_HEIGHT);
            txtPlayer.setBackgroundColor(Color.TRANSPARENT);
            txtPlayer.setTypeface(null, Typeface.BOLD);
            txtPlayer.setTextColor(Color.WHITE);
            txtPlayer.setSingleLine();
            txtPlayer.setEllipsize(TruncateAt.END);

            txtPlayer.setOnClickListener(playerClickListener);
            //this.addView(txtPlayer);
            statRow.removeViewAt(0);
            statRow.addView(txtPlayer, 0);
        }

        statScore.setText(Integer.toString(lastScore));
        statLeadingGamesCount.setText(Integer.toString(leadingGamesCount));
        statSuccessfulGamesCount.setText(
                Integer.toString(successfulLeadingGamesCount) + " (" + Integer.toString(successRate) + "%)");

        // display called game count if necessary 
        if (this.getGameSet().getGameStyleType() == GameStyleType.Tarot5) {
            TextView statCalledGamesCount = (TextView) statRow.findViewById(R.id.statCalledGamesCount);
            statCalledGamesCount
                    .setText(Integer.toString(calledCount.get(player) == null ? 0 : calledCount.get(player)));
        }

        statMinScore.setText(Integer.toString(minScoreForPlayer));
        statMaxScore.setText(Integer.toString(maxScoreForPlayer));
        statMinScore.setTextColor(Color.WHITE);
        statMaxScore.setTextColor(Color.WHITE);

        // color min score if lowest
        if (minScoreEver == minScoreForPlayer) {
            statMinScore.setTextColor(Color.YELLOW);
        }

        // color max score if highest
        if (maxScoreEver == maxScoreForPlayer) {
            statMaxScore.setTextColor(Color.GREEN);
        }
    }
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override/* w  w  w  . java2s  .  c o  m*/
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0
                        && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.primary_text));
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null,
                    null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon),
                    null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}

From source file:com.ch.ch_library.smartlayout.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   w ww.  j a v a 2  s  .  c  om
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(mTabViewTextColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(mTabViewTextAllCaps);
    }

    textView.setPadding(mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0);

    if (mTabViewTextMinWidth > 0) {
        textView.setMinWidth(mTabViewTextMinWidth);
    }

    return textView;
}

From source file:com.shichai.www.choume.view.tab.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   ww w . j  a  va  2s  . com
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(mTabViewTextColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(mTabViewTextAllCaps);
    }

    textView.setPadding(mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0);

    if (mTabViewTextMinWidth > 0) {
        textView.setMinWidth(mTabViewTextMinWidth);
    }

    return textView;
}

From source file:com.socialinfotech.tabbar.smart.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.// ww w  .  j a  v a 2  s. c  o m
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(mTabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(mTabViewTextAllCaps);
    }

    textView.setPadding(mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0);

    if (mTabViewTextMinWidth > 0) {
        textView.setMinWidth(mTabViewTextMinWidth);
    }

    return textView;
}

From source file:com.open.imooc.widght.tab.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*www .  j a v  a  2 s. c om*/
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    //        textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        textView.setBackgroundResource(tabViewBackgroundResId);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(tabViewTextAllCaps);
    }

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}

From source file:com.jinzht.pro.smarttablayout.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*  www  .  ja  v a2  s.co  m*/
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setSingleLine(true);
    UiHelp.textBold(textView);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        textView.setBackgroundResource(tabViewBackgroundResId);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(tabViewTextAllCaps);
    }

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}