Example usage for android.widget TextView setLayoutParams

List of usage examples for android.widget TextView setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:ca.rmen.android.scrumchatter.chart.ChartUtils.java

static void addLegendEntry(Context context, ViewGroup legendView, String name, int color) {
    TextView memberLegendEntry = new TextView(context);
    memberLegendEntry.setText(name);/*w  w  w  .  j  a  v  a 2 s  . c  o m*/
    memberLegendEntry.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    memberLegendEntry.setPadding(0, 0,
            context.getResources().getDimensionPixelSize(R.dimen.chart_legend_entry_padding), 0);

    final Drawable icon;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square);
        memberLegendEntry.setTextColor(color);
    } else {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square).mutate();
        DrawableCompat.setTint(icon, color);
    }
    memberLegendEntry.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    legendView.addView(memberLegendEntry);
}

From source file:Main.java

protected static Bitmap creatCodeBitmap(String contents, int width, int height, Context context) {
    TextView tv = new TextView(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(layoutParams);
    tv.setText(contents);//from www.ja v  a 2 s.c  o m
    tv.setHeight(height);
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    tv.setWidth(width);
    tv.setDrawingCacheEnabled(true);
    tv.setTextColor(Color.BLACK);
    tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

    tv.buildDrawingCache();
    Bitmap bitmapCode = tv.getDrawingCache();
    return bitmapCode;
}

From source file:android.support.v17.leanback.app.ErrorSupportFragment.java

private static void setTopMargin(TextView textView, int topMargin) {
    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) textView.getLayoutParams();
    lp.topMargin = topMargin;/*from w  w w  .  j  ava2  s  .  c o m*/
    textView.setLayoutParams(lp);
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static TextView getTextView(Context context, LinearLayout.LayoutParams params, StringBuffer buffer) {
    TextView textView = new TextView(context);
    textView.setTextColor(Color.BLACK);
    textView.setLayoutParams(params);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setTextSize(getTextSize(context));
    textView.setText(Html.fromHtml(buffer.toString()));
    return textView;
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static void addImgLinkText(final Context context, ArrayList<View> views, final String url,
        LinearLayout.LayoutParams params) {
    final TextView textView = new TextView(context);
    textView.setTextColor(Color.BLUE);
    textView.setLayoutParams(params);
    textView.setText("View image");
    textView.setTextSize(getTextSize(context));
    textView.setPadding(3, 3, 3, 3);//from  w  w w  .ja  va  2  s . c  om
    textView.setTag(url);
    textView.setClickable(true);
    setupOnLinkClick(context, url, textView);
    views.add(textView);
}

From source file:com.ouyangzn.github.utils.UiUtils.java

public static TextView setCenterTitle(Toolbar toolbar, String title) {
    TextView titleView = new TextView(toolbar.getContext());
    titleView.setGravity(Gravity.CENTER);
    titleView.setTextAppearance(toolbar.getContext(), R.style.Toolbar_titleTextAppearance);
    titleView.setSingleLine();//from   w  ww . ja v  a  2 s  .c om
    titleView.setEllipsize(TextUtils.TruncateAt.END);
    titleView.setText(title);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    titleView.setLayoutParams(params);
    Toolbar.LayoutParams lp = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    lp.gravity = Gravity.CENTER;
    toolbar.addView(titleView, lp);
    return titleView;
}

From source file:com.fjoglar.etsitnoticias.utils.UiUtils.java

/**
 * Configure the TextViews that will show the attachments of the new.
 *
 * @param textView      TextView to be configured.
 * @param title         Text shown in TextView
 * @param downloadLink  Link attached to TextView.
 * @param fileType      Type of file of the attachment.
 * @param context       The context of activity.
 *///from   www.ja  v a 2  s  .c  o m
public static void configureTextView(TextView textView, String title, final String downloadLink,
        Attachment.FILE_TYPE fileType, final Context context) {

    final int TEXT_VIEW_MIN_HEIGHT = 40;
    final int TEXT_VIEW_MARGIN_TOP = 4;

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, convertDpToPx(TEXT_VIEW_MARGIN_TOP, context), 0, 0);
    textView.setLayoutParams(params);

    textView.setText(title);
    textView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
    textView.setMinHeight(convertDpToPx(TEXT_VIEW_MIN_HEIGHT, context));
    textView.setGravity(Gravity.CENTER_VERTICAL);

    switch (fileType) {
    case FILE:
        textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_file, 0, 0, 0);
        break;
    case IMAGE:
        textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_photo, 0, 0, 0);
        break;
    case FOLDER:
        textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_folder, 0, 0, 0);
        break;
    default:
        textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_link, 0, 0, 0);
        break;
    }

    textView.setCompoundDrawablePadding(convertDpToPx(4, context));

    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
    textView.setBackgroundResource(typedValue.resourceId);

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Navigator.getInstance().openUrl(context, downloadLink);
        }
    });
}

From source file:it.enricocandino.ssv.sample.ScrollableFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_synchronized_scroll_view, container, false);

    LinearLayout rowContainer = (LinearLayout) rootView.findViewById(R.id.container);

    int fragmentColor = getArguments().getInt("color", 0xFFF44336);

    int count = 1;
    for (int opacity = 63; opacity < 256; opacity += 16) {

        TextView row = new TextView(getContext());
        row.setLayoutParams(new SynchronizedScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 250));
        row.setGravity(Gravity.CENTER);//from w  w  w  .j av  a2  s . com

        row.setBackgroundColor(fragmentColor);
        row.getBackground().setAlpha(opacity);
        row.setText(String.valueOf(count++));

        rowContainer.addView(row);
    }

    return rootView;
}

From source file:com.adstrosoftware.animationplayground.InvalidFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    TextView textView = new TextView(getActivity());

    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    textView.setText(R.string.illegalAnimation);
    textView.setGravity(Gravity.CENTER);

    return textView;
}

From source file:com.adstrosoftware.gpsplayground.InvalidFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    TextView textView = new TextView(getActivity());

    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    textView.setText(R.string.illegalFeature);
    textView.setGravity(Gravity.CENTER);

    return textView;
}