Example usage for android.view View setPadding

List of usage examples for android.view View setPadding

Introduction

In this page you can find the example usage for android.view View setPadding.

Prototype

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

Source Link

Document

Sets the padding.

Usage

From source file:com.github.takumalee.simplematerialtabpager.view.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        //            v.setBackgroundResource(tabBackgroundColor != 0 ? tabBackgroundColor : tabBackgroundResId);
        v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom());

        if (v instanceof TextView) {
            TextView tabText = (TextView) v.findViewById(R.id.psts_tab_title);

            if (tabText != null) {
                tabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tabText.setAllCaps(true);
                    } else {
                        tabText.setText(tabText.getText().toString().toUpperCase(locale));
                    }/*from  w  w  w  .  j  a  va  2 s .  com*/
                }
            }
        }

    }
}

From source file:com.example.view.astuetz.PagerSlidingTabStrip.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);/*ww w  .  ja v a2  s. c om*/
    tab.setClickable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                pager.setCurrentItem(position);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    tab.setPadding(tabPadding, tabPaddingTop, tabPadding, tabPaddingTop);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
    LinearLayout.LayoutParams le = (android.widget.LinearLayout.LayoutParams) tab.getLayoutParams();
    le.weight = 1;
    tab.setLayoutParams(le);
}

From source file:com.tpos.widget.pagertab.PagerSlidingTabStrip.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);//  w w  w.  j av  a2s. c  o m
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    //      tab.setLayoutParams(new LinearLayout.LayoutParams(
    //            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.trimph.toprand.trimphrxandroid.trimph.ui.main.news.view.PagerSlidingTabStrip.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);//from  w  ww. j av  a  2  s.c  o  m
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
            if (onTabStripItemCickListener != null && currentPosition == position) {
                onTabStripItemCickListener.onTabStripItemCickListener(v, position);
            }
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tab.setId(position);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:org.nuxeo.android.layout.WidgetDefinition.java

public NuxeoWidget build(LayoutContext context, Document doc, ViewGroup parent, LayoutMode mode) {
    this.mode = mode;

    View view = null;
    LayoutParams labelLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 1f);
    LayoutParams widgetLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 1f);

    if (LayoutMode.VIEW == mode) {
        labelLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
                0.6f);/*from   ww w.ja v  a  2s .  com*/
        widgetLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
                0.4f);
    }

    AndroidWidgetWrapper wrapper = AndroidWidgetMapper.getInstance().getWidgetWrapper(this);

    if (wrapper != null) {
        view = wrapper.buildView(context, mode, doc, attributeNames, this);
        view.setLayoutParams(widgetLayoutParams);
        view.setPadding(1, 1, 1, 1);
        if (LayoutMode.VIEW == mode) {
            view.setBackgroundColor(Color.rgb(240, 240, 250));
        }
    }

    if (view != null) {
        if (label != null) {
            TextView labelW = new TextView(context.getActivity());
            labelW.setText(label + " :");
            labelW.setTextColor(Color.rgb(80, 80, 80));
            labelW.setLayoutParams(labelLayoutParams);
            parent.addView(labelW);
            if (LayoutMode.VIEW != mode) {
                labelW.setBackgroundColor(Color.rgb(160, 160, 170));
                labelW.setTextColor(Color.rgb(20, 20, 40));
                labelW.setPadding(5, 5, 5, 5);
            }

        }
        parent.addView(view);
        return new NuxeoWidget(this, view, wrapper);
    }

    return null;
}

From source file:net.gnu.common.view.SlidingHorizontalScroll.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        View tabView = null;
        TextView tabTitleView = null;//from  ww  w.j a v a2  s  . c  o m

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStripLinearLayout, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if ((fra == null || fra.circular()) && (i == 0 || i == count - 1) && count > 1) {
            final int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
            tabView.setPadding(0, padding >> 2, 0, padding >> 2);
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabTitleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
        tabTitleView.setMaxEms(9);
        tabTitleView.setSingleLine(true);
        tabView.setOnClickListener(tabClickListener);

        tabTitleView.setTextColor(ExplorerActivity.TEXT_COLOR);

        mTabStripLinearLayout.addView(tabView);
    }
    mTabStripLinearLayout.setBackgroundColor(ExplorerActivity.BASE_BACKGROUND);
}

From source file:com.murrayc.galaxyzoo.app.QuestionFragment.java

private static void insertButtonInRow(final Context context, final TableRow row, final View button) {
    final TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT,
            1f /* weight */);
    //Use as little padding as possible at the left and right because the button
    //will usually get extra space from the TableLayout anyway,
    //but we want to avoid ugly line-breaks when the text is long (such as in translations).

    //Space around the inside of the buttons:
    //When we use smaller dp values, there seems to be no padding at the sides at all,
    //probably because the edges of the button are actually dependent on the standard background
    //image for buttons.
    //2 * standard_margin is nicer, but there is usually more, because the buttons expand
    //and a too-small margin is better than splitting a word across lines.
    final int padding = UiUtils.getPxForDpResource(context, R.dimen.small_margin);
    button.setPadding(padding, button.getPaddingTop(), padding, padding);

    if (row.getChildCount() > 0) {
        //Space between the buttons:
        final int margin = UiUtils.getPxForDpResource(context, R.dimen.tiny_gap);
        params.setMargins(margin, 0, 0, 0);
        // When using the standard background drawable (not our custom background color
        // which replaces it) This reduces the space caused by the standard background drawable,
        // but negative margins are unmaintainable voodoo:
        // params.setMargins(-4, 0, -4, 0);
    }/*from  www. jav  a2  s .com*/

    row.addView(button, params);
}

From source file:com.facebook.litho.MountState.java

private static void unsetViewPadding(View view, ViewNodeInfo viewNodeInfo) {
    if (!viewNodeInfo.hasPadding()) {
        return;//ww  w  .j  a v a2 s  .c o m
    }

    view.setPadding(0, 0, 0, 0);
}

From source file:com.facebook.litho.MountState.java

private static void setViewPadding(View view, ViewNodeInfo viewNodeInfo) {
    if (!viewNodeInfo.hasPadding()) {
        return;/*from   w ww. j a  va2  s. co  m*/
    }

    view.setPadding(viewNodeInfo.getPaddingLeft(), viewNodeInfo.getPaddingTop(), viewNodeInfo.getPaddingRight(),
            viewNodeInfo.getPaddingBottom());
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
 * //from w  ww  . j av a2s.  c  om
 * @param view
 */
private void displayResult(View view, LayoutInflater inflater, ViewGroup vg) {
    /*
     final Button shareButton = (Button) view.findViewById(R.id.resultButtonShare);
     if (shareButton != null)
    shareButton.setEnabled(false);
    */

    //final LinearLayout measurementLayout = (LinearLayout) view.findViewById(R.id.resultMeasurementList);
    measurementLayout = (LinearLayout) view.findViewById(R.id.resultMeasurementList);
    measurementLayout.setVisibility(View.GONE);

    final LinearLayout resultLayout = (LinearLayout) view.findViewById(R.id.result_layout);
    resultLayout.setVisibility(View.INVISIBLE);

    final LinearLayout netLayout = (LinearLayout) view.findViewById(R.id.resultNetList);
    netLayout.setVisibility(View.GONE);

    final TextView measurementHeader = (TextView) view.findViewById(R.id.resultMeasurement);
    measurementHeader.setVisibility(View.GONE);

    final TextView netHeader = (TextView) view.findViewById(R.id.resultNet);
    netHeader.setVisibility(View.GONE);

    final TextView emptyView = (TextView) view.findViewById(R.id.infoText);
    emptyView.setVisibility(View.GONE);
    final float scale = activity.getResources().getDisplayMetrics().density;

    final ProgressBar progessBar = (ProgressBar) view.findViewById(R.id.progressBar);

    if (testResult != null && testResult.length() > 0) {

        JSONObject resultListItem;

        try {
            resultListItem = testResult.getJSONObject(0);

            openTestUuid = resultListItem.optString("open_test_uuid");
            if (graphView != null) {
                graphView.setOpenTestUuid(openTestUuid);
                graphView.initialize(graphViewEndTaskListener);
            }

            JSONObject testResultItem;
            try {
                testResultItem = testResult.getJSONObject(0);
                if (testResultItem.has("geo_lat") && testResultItem.has("geo_long") && !hasMap) {
                    hasMap = true;
                    if (dataChangedListener != null) {
                        dataChangedListener.onChange(false, true, "HAS_MAP");
                    }
                    notifyDataSetChanged();
                } else if (!testResultItem.has("geo_lat") && !testResultItem.has("geo_long") && hasMap) {
                    System.out.println("hasMap = " + hasMap);
                    hasMap = false;
                    if (dataChangedListener != null) {
                        dataChangedListener.onChange(true, false, "HAS_MAP");
                    }
                    notifyDataSetChanged();
                }
            } catch (JSONException e) {
                hasMap = false;
                e.printStackTrace();
            }

            if (completeListener != null) {
                completeListener.onComplete(OnCompleteListener.DATA_LOADED, this);
            }

            final JSONArray measurementArray = resultListItem.getJSONArray("measurement");

            final JSONArray netArray = resultListItem.getJSONArray("net");

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

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

                final View measurementItemView = inflater.inflate(R.layout.classification_list_item, vg, false);

                final JSONObject singleItem = measurementArray.getJSONObject(i);

                final TextView itemTitle = (TextView) measurementItemView
                        .findViewById(R.id.classification_item_title);
                itemTitle.setText(singleItem.getString("title"));

                final ImageView itemClassification = (ImageView) measurementItemView
                        .findViewById(R.id.classification_item_color);
                itemClassification.setImageResource(
                        Helperfunctions.getClassificationColor(singleItem.getInt("classification")));

                itemClassification.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        activity.showHelp(R.string.url_help_result, false);
                    }
                });

                final TextView itemValue = (TextView) measurementItemView
                        .findViewById(R.id.classification_item_value);
                itemValue.setText(singleItem.getString("value"));

                measurementLayout.addView(measurementItemView);

                final View divider = new View(activity);
                divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv, 1));
                divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                measurementLayout.addView(divider);

                measurementLayout.invalidate();
            }

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

                final JSONObject singleItem = netArray.getJSONObject(i);

                addResultListItem(singleItem.getString("title"), singleItem.optString("value", null),
                        netLayout);
            }

            addQoSResultItem();

        } catch (final JSONException e) {
            e.printStackTrace();
        }

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);

        resultLayout.setVisibility(View.VISIBLE);
        measurementHeader.setVisibility(View.VISIBLE);
        netHeader.setVisibility(View.VISIBLE);

        measurementLayout.setVisibility(View.VISIBLE);
        netLayout.setVisibility(View.VISIBLE);

    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(activity.getString(R.string.error_no_data));
        emptyView.invalidate();
    }
}