Example usage for android.widget TextView setPadding

List of usage examples for android.widget TextView setPadding

Introduction

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

Prototype

@Override
public void setPadding(int left, int top, int right, int bottom) 

Source Link

Usage

From source file:com.jimish.material.sample.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 ww w. j a va 2 s  .  co  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

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

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);

    return textView;
}

From source file:com.hanks.zhe800.ui.view.tabs.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  ww. ja v a2 s.c o m
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    //        textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    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.health.openscale.gui.TableFragment.java

@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList) {
    TableRow headerRow = (TableRow) tableView.findViewById(R.id.tableHeader);
    tableDataView.removeAllViews();// w  w w.  j  ava2 s  .  c om
    tableDataView.addView(headerRow);

    for (ScaleData scaleData : scaleDataList) {
        TableRow dataRow = new TableRow(tableView.getContext());
        dataRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        TextView idView = new TextView(tableView.getContext());
        idView.setText(Long.toString(scaleData.id));
        idView.setVisibility(View.GONE);
        dataRow.addView(idView);

        TextView dateTextView = new TextView(tableView.getContext());
        if ((getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE
                || (getResources().getConfiguration().screenLayout
                        & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
            dateTextView.setText(new SimpleDateFormat("dd. MMM yyyy (EE)").format(scaleData.date_time));
        } else {
            dateTextView.setText(new SimpleDateFormat("dd/MM/yy").format(scaleData.date_time));
        }
        dateTextView.setPadding(0, 5, 5, 5);
        dataRow.addView(dateTextView);

        TextView timeTextView = new TextView(tableView.getContext());
        timeTextView.setText(new SimpleDateFormat("HH:mm").format(scaleData.date_time));
        timeTextView.setPadding(0, 5, 5, 5);
        dataRow.addView(timeTextView);

        TextView weightView = new TextView(tableView.getContext());
        weightView.setText(Float.toString(scaleData.weight));
        weightView.setPadding(0, 5, 5, 5);
        dataRow.addView(weightView);

        TextView fatView = new TextView(tableView.getContext());
        fatView.setText(Float.toString(scaleData.fat));
        fatView.setPadding(0, 5, 5, 5);
        dataRow.addView(fatView);

        TextView waterView = new TextView(tableView.getContext());
        waterView.setText(Float.toString(scaleData.water));
        waterView.setPadding(0, 5, 5, 5);
        dataRow.addView(waterView);

        TextView muscleView = new TextView(tableView.getContext());
        muscleView.setText(Float.toString(scaleData.muscle));
        muscleView.setPadding(0, 5, 5, 5);
        dataRow.addView(muscleView);

        Button deleteButton = new Button(tableView.getContext());
        deleteButton.setText("X");
        deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
        deleteButton.setTextColor(Color.WHITE);
        deleteButton.setBackgroundResource(R.drawable.flat_selector);
        deleteButton.setGravity(Gravity.CENTER);
        deleteButton.setPadding(0, 0, 0, 0);
        deleteButton.setMinimumHeight(35);
        deleteButton.setHeight(35);
        deleteButton.setOnClickListener(new onClickListenerDelete());
        dataRow.addView(deleteButton);

        if ((getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE
                && (getResources().getConfiguration().screenLayout
                        & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_LARGE) {
            dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            timeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            weightView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            fatView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            waterView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
            muscleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
        }

        tableDataView.addView(dataRow,
                new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:com.kayumov.abduaziz.gilde.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)}.//ww  w  .java  2 s. c om
 */
protected TextView createDefaultTabView(Context context) {

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(Color.WHITE);

    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

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

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

    return textView;
}

From source file:com.indev.calculator.widget.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  .ja v a  2 s .  c o m
 */

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

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

    return textView;
}

From source file:at.alladin.rmbt.android.fragments.history.RMBTFilterFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    view = inflater.inflate(R.layout.history_filter, container, false);

    deviceListView = (LinearLayout) view.findViewById(R.id.deviceList);
    networkListView = (LinearLayout) view.findViewById(R.id.networkList);

    final RelativeLayout resultLimitView = (RelativeLayout) view.findViewById(R.id.Limit25Wrapper);
    limit25CheckBox = (CheckBox) view.findViewById(R.id.Limit25CheckBox);

    if (activity.getHistoryResultLimit() == 250)
        limit25CheckBox.setChecked(true);
    else// ww w.java2s  .  c  om
        limit25CheckBox.setChecked(false);

    resultLimitView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            if (limit25CheckBox.isChecked()) {
                limit25CheckBox.setChecked(false);
                activity.setHistoryResultLimit(0);
            } else {
                limit25CheckBox.setChecked(true);
                activity.setHistoryResultLimit(250);
            }

        }

    });

    devicesToShow = activity.getHistoryFilterDevicesFilter();
    networksToShow = activity.getHistoryFilterNetworksFilter();

    if (devicesToShow == null && networksToShow == null) {
        devicesToShow = new ArrayList<String>();
        networksToShow = new ArrayList<String>();
    }

    final float scale = activity.getResources().getDisplayMetrics().density;

    final int leftRightItem = Helperfunctions.dpToPx(5, scale);
    // int topBottomItem = Helperfunctions.dpToPx(5, scale);

    // int leftRightDiv = Helperfunctions.dpToPx(0, scale);
    // int topBottomDiv = Helperfunctions.dpToPx(0, scale);
    final int heightDiv = Helperfunctions.dpToPx(1, scale);

    // int topBottomImg = Helperfunctions.dpToPx(1, scale);

    final String historyDevices[] = activity.getHistoryFilterDevices();

    if (historyDevices != null) {

        for (int i = 0; i < historyDevices.length; i++) {

            final RelativeLayout singleItemLayout = new RelativeLayout(activity); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

            singleItemLayout.setId(i);
            singleItemLayout.setClickable(true);
            singleItemLayout.setBackgroundResource(R.drawable.list_selector);

            singleItemLayout.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            final TextView itemTitle = new TextView(activity, null, R.style.textMediumLight);

            RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemTitle.setLayoutParams(layout);
            itemTitle.setGravity(Gravity.LEFT);
            itemTitle.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemTitle.setText(historyDevices[i]);

            singleItemLayout.addView(itemTitle, layout);

            final CheckBox itemCheck = new CheckBox(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemCheck.setLayoutParams(layout);

            itemCheck.setGravity(Gravity.RIGHT);
            itemCheck.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemCheck.setOnClickListener(null);
            itemCheck.setClickable(false);
            itemCheck.setId(i + historyDevices.length);

            if (devicesToShow.isEmpty() || devicesToShow.contains(historyDevices[i]))
                itemCheck.setChecked(true);
            else
                itemCheck.setChecked(false);

            singleItemLayout.addView(itemCheck, layout);

            // layout = new
            // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
            // RelativeLayout.LayoutParams.WRAP_CONTENT);

            // singleItemLayout.setLayoutParams(layout);

            singleItemLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    final CheckBox check = (CheckBox) v.findViewById(v.getId() + historyDevices.length);
                    if (check.isChecked()) {
                        check.setChecked(false);
                        devicesToShow.remove(historyDevices[v.getId()]);
                    } else {
                        check.setChecked(true);
                        devicesToShow.add(historyDevices[v.getId()]);
                    }

                }

            });

            deviceListView.addView(singleItemLayout);

            final View divider = new View(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv);

            divider.setBackgroundResource(R.drawable.bg_trans_light_10);

            deviceListView.addView(divider, layout);

        }
        deviceListView.invalidate();
    }

    final String historyNetworks[] = activity.getHistoryFilterNetworks();

    if (historyNetworks != null) {

        for (int i = 0; i < historyNetworks.length; i++) {

            final RelativeLayout singleItemLayout = new RelativeLayout(activity); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

            singleItemLayout.setId(i);
            singleItemLayout.setClickable(true);
            singleItemLayout.setBackgroundResource(R.drawable.list_selector);

            singleItemLayout.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            final TextView itemTitle = new TextView(activity, null, R.style.textMediumLight);
            RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemTitle.setLayoutParams(layout);
            itemTitle.setGravity(Gravity.LEFT);
            itemTitle.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemTitle.setText(historyNetworks[i]);

            singleItemLayout.addView(itemTitle, layout);

            final CheckBox itemCheck = new CheckBox(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemCheck.setLayoutParams(layout);

            itemCheck.setGravity(Gravity.RIGHT);
            itemCheck.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemCheck.setOnClickListener(null);
            itemCheck.setClickable(false);
            itemCheck.setId(i + historyNetworks.length);

            if (networksToShow.isEmpty() || networksToShow.contains(historyNetworks[i]))
                itemCheck.setChecked(true);
            else
                itemCheck.setChecked(false);

            singleItemLayout.addView(itemCheck, layout);

            singleItemLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    final CheckBox check = (CheckBox) v.findViewById(v.getId() + historyNetworks.length);
                    if (check.isChecked()) {
                        check.setChecked(false);
                        networksToShow.remove(historyNetworks[v.getId()]);
                    } else {
                        check.setChecked(true);
                        networksToShow.add(historyNetworks[v.getId()]);
                    }
                    System.out.println(networksToShow.toString());
                }

            });

            networkListView.addView(singleItemLayout);

            final View divider = new View(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv);

            divider.setBackgroundResource(R.drawable.bg_trans_light_10);

            networkListView.addView(divider, layout);

        }
        networkListView.invalidate();
    }
    /*
     * // Set option as Multiple Choice. So that user can able to select
     * more the one option from list deviceListView.setAdapter(new
     * ArrayAdapter<String>(activity,
     * android.R.layout.simple_list_item_multiple_choice, historyDevices));
     * deviceListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
     * 
     * for (int i = 0; i < historyDevices.length; i++) {
     * //deviceListView.setItemChecked(i, true); }
     * 
     * deviceListView.setOnItemClickListener(new OnItemClickListener() {
     * 
     * @Override public void onItemClick(AdapterView<?> l, View v, int
     * position, long id) {
     * 
     * }
     * 
     * });
     * 
     * 
     * // Set option as Multiple Choice. So that user can able to select
     * more the one option from list networkListView.setAdapter(new
     * ArrayAdapter<String>(activity,
     * android.R.layout.simple_list_item_multiple_choice, networkDevices));
     * networkListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
     * 
     * for (int i = 0; i < networkDevices.length; i++) {
     * networkListView.setItemChecked(i, true); }
     * 
     * SparseBooleanArray checked =
     * deviceListView.getCheckedItemPositions(); ArrayList<String>
     * devicesToShow = new ArrayList<String>(); for(int i = 0; i <
     * checked.size()+1; i++){ if(checked.get(i))
     * devicesToShow.add(historyDevices[i]); }
     */

    return view;
}

From source file:com.example.admin.viewpageexample.SlidingTab.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  ww  w  .j  a v a 2s  .  c o  m*/
 */
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

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

    return textView;
}

From source file:br.comoferta.ui.view.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)}./*w w w  .  j av a 2s.  co m*/
 */
protected TextView createDefaultTabView(Context context) {
    ColorStateList colorStateList = new ColorStateList(new int[][] {
            new int[] { android.R.attr.state_selected }, new int[] { -android.R.attr.state_selected }, },
            new int[] { Color.WHITE, Color.LTGRAY });

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTextColor(colorStateList);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

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

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

    return textView;
}

From source file:com.example.lance.rxjavatest.customview.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. ja va  2 s  .  com*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setTextColor(getResources().getColorStateList(R.color.textview));
    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.example.zapbuild.baseclasses.util.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. j  av  a2s  . c o m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

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

    //        textView.setAllCaps(true);

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

    return textView;
}