Example usage for android.widget TextView setGravity

List of usage examples for android.widget TextView setGravity

Introduction

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

Prototype

public void setGravity(int gravity) 

Source Link

Document

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

Usage

From source file:com.hongbaogou.view.PagerSlidingTabStrip.java

public void addTextTab(final int position, String title) {

    //      TextView tab = new TextView(getContext());
    TextView tab = (TextView) View.inflate(getContext(), R.layout.list_item, null);
    //      tab.setTextSize(Dip2PxUtils.sp2px(getContext(),25));
    //      tab.setTextSize(50);
    tab.setText(title);// w  ww.j a va2s . c  om
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:edu.cnu.PowerTutor.ui.PowerViewer.java

public void refreshView() {
    if (counterService == null) {
        TextView loadingText = new TextView(this);
        loadingText.setText("Waiting for profiler service...");
        loadingText.setGravity(Gravity.CENTER);
        setContentView(loadingText);/*  ww w.  j  a  v  a2s. co m*/
        return;
    }

    chartLayout = new LinearLayout(this);
    chartLayout.setOrientation(LinearLayout.VERTICAL);

    if (uid == SystemInfo.AID_ALL) {
        /*
         * If we are reporting global power usage then just set noUidMask to
         * 0 so that all components get displayed.
         */
        noUidMask = 0;
    }
    components = 0;
    for (int i = 0; i < componentNames.length; i++) {
        if ((noUidMask & 1 << i) == 0) {
            components++;
        }
    }
    boolean showTotal = prefs.getBoolean("showTotalPower", false);
    collectors = new ValueCollector[(showTotal ? 1 : 0) + components];

    int pos = 0;
    for (int i = showTotal ? -1 : 0; i < componentNames.length; i++) {
        if (i != -1 && (noUidMask & 1 << i) != 0) {
            continue;
        }
        String name = i == -1 ? "Total" : componentNames[i];
        double mxPower = (i == -1 ? 2100.0 : componentsMaxPower[i]) * 1.05;

        XYSeries series = new XYSeries(name);
        XYMultipleSeriesDataset mseries = new XYMultipleSeriesDataset();
        mseries.addSeries(series);

        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        XYSeriesRenderer srenderer = new XYSeriesRenderer();
        renderer.setYAxisMin(0.0);
        renderer.setYAxisMax(mxPower);
        renderer.setYTitle(name + "(mW)");

        int clr = PowerPie.COLORS[(PowerPie.COLORS.length + i) % PowerPie.COLORS.length];
        srenderer.setColor(clr);
        srenderer.setFillBelowLine(true);
        srenderer.setFillBelowLineColor(((clr >> 1) & 0x7F7F7F) | (clr & 0xFF000000));
        renderer.addSeriesRenderer(srenderer);

        View chartView = new GraphicalView(this, new CubicLineChart(mseries, renderer, 0.5f));
        chartView.setMinimumHeight(100);
        chartLayout.addView(chartView);

        collectors[pos] = new ValueCollector(series, renderer, chartView, i);
        if (handler != null) {
            // Main Handler?   . (debug)
            handler.post(collectors[pos]);
        }
        pos++;
    }

    /*
     * We're giving 100 pixels per graph of vertical space for the chart
     * view. If we don't specify a minimum height the chart view ends up
     * having a height of 0 so this is important.
     */
    chartLayout.setMinimumHeight(100 * components);

    ScrollView scrollView = new ScrollView(this);
    scrollView.addView(chartLayout);
    setContentView(scrollView);
}

From source file:com.earthsea.fish.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  .j  a  v a  2s  .c  o m*/
 */
protected TextView createDefaultTabView(Context context) {

    //        String activity = context.toString();
    //
    //        Log.v("tab_context",activity);
    //
    TextView textView = new TextView(context);
    //
    //        if (activity.contains("SingleReport")) {

    //            textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));

    //        }

    // Instead of messing with layout params maybe we should crank up the padding when we know the
    // number of tab items will be low but we don't want them to be crammed into the view width

    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));

    /*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(true);
    }

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

    textView.setPadding(40, padding, 40, padding);

    return textView;
}

From source file:com.lite.android.launcher3.allapps.AllAppsGridAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    boolean hideIconLabels = SettingsProvider.getBoolean(mLauncher,
            SettingsProvider.SETTINGS_UI_DRAWER_HIDE_ICON_LABELS,
            R.bool.preferences_interface_drawer_hide_icon_labels_default);
    FastScrollFocusApplicator.setFastScrollDimmed(holder.mContent, false, false);
    FastScrollFocusApplicator.setFastScrollFocused(holder.mContent, false, false);
    switch (holder.getItemViewType()) {
    case ICON_VIEW_TYPE: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.setTextColor(mAllAppsTextColor);
        if (hideIconLabels) {
            icon.setTextVisibility(!hideIconLabels);
        }//www.jav  a 2  s  .co m
        icon.applyFromApplicationInfo(info);
        FastScrollFocusApplicator.setFastScrollDimmed(icon, shouldDimPosition(position), !mIconsDimmed);
        FastScrollFocusApplicator.setFastScrollFocused(icon, false, !mIconsDimmed);
        break;
    }
    case PREDICTION_ICON_VIEW_TYPE: {
        AppInfo info = mApps.getAdapterItems().get(position).appInfo;
        BubbleTextView icon = (BubbleTextView) holder.mContent;
        icon.setTextColor(mAllAppsTextColor);
        if (hideIconLabels) {
            icon.setTextVisibility(!hideIconLabels);
        }
        icon.applyFromApplicationInfo(info);
        FastScrollFocusApplicator.setFastScrollDimmed(icon, shouldDimPosition(position), !mIconsDimmed);
        FastScrollFocusApplicator.setFastScrollFocused(icon, false, !mIconsDimmed);

        mRemoteFolderManager.onBindViewHolder(holder, info);
        break;
    }
    case EMPTY_SEARCH_VIEW_TYPE:
        TextView emptyViewText = (TextView) holder.mContent;
        emptyViewText.setText(mEmptySearchMessage);
        emptyViewText.setGravity(
                mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
        break;
    case SEARCH_MARKET_VIEW_TYPE:
        TextView searchView = (TextView) holder.mContent;
        if (mMarketSearchIntent != null) {
            searchView.setVisibility(View.VISIBLE);
            searchView.setContentDescription(mMarketSearchMessage);
            searchView.setGravity(
                    mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
            searchView.setText(mMarketSearchMessage);
        } else {
            searchView.setVisibility(View.GONE);
        }
        break;
    case CUSTOM_PREDICTED_APPS_HEADER_VIEW_TYPE: {
        TextView title = (TextView) holder.mContent.findViewById(R.id.title);
        title.setTextColor(mAllAppsTextColor);
        FastScrollFocusApplicator.setFastScrollDimmed(holder.mContent, shouldDimPosition(position),
                !mIconsDimmed);
        FastScrollFocusApplicator.setFastScrollFocused(holder.mContent, false, !mIconsDimmed);

        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) holder.mContent.getLayoutParams();
        mCustomPredictedAppsHeaderHeight = holder.mContent.getHeight() + lp.topMargin + lp.bottomMargin;
        break;
    }
    case CUSTOM_PREDICTED_APPS_FOOTER_VIEW_TYPE:
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) holder.mContent.getLayoutParams();
        mCustomPredictedAppsFooterHeight = holder.mContent.getHeight() + lp.topMargin + lp.bottomMargin;
    }
}

From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java

/** add one number indicator tab */
private void addNumTab(final int position, String title, int num) {
    LinearLayout tab = new LinearLayout(getContext());
    TextView titleText = new TextView(getContext());
    TextView numText = new TextView(getContext());

    titleText.setText(title);//from w  w w  . j  a v  a 2  s.  c om
    titleText.setGravity(Gravity.CENTER);
    titleText.setSingleLine();

    numText.setText(Integer.toString(num));
    numText.setGravity(Gravity.CENTER);
    numText.setPadding(mNumPadding, 1, mNumPadding, 1);
    numText.setSingleLine();

    /* if the number is 0, set invisible */
    if (num == 0) {
        numText.setVisibility(View.GONE);
    } else {
        numText.setVisibility(View.VISIBLE);
    }

    tab.addView(titleText, 0, mDefaultTabLayoutParams);
    tab.addView(numText, 1, mNumLayoutParams);
    tab.setGravity(Gravity.CENTER);

    addTab(position, tab);
}

From source file:com.hcpt.fastfood.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position) {

    TextView tab = new TextView(getContext());
    if (!arrTabs.isEmpty()) {
        // Set text
        tab.setText(arrTabs.get(position).getTitle());
        tab.setTypeface(null, Typeface.BOLD);
        tab.setGravity(Gravity.CENTER_HORIZONTAL);
        tab.setSingleLine();//w w w  . j  a v a2 s  .com

        // Set icon

        Drawable iconDrawable = getResources().getDrawable(arrTabs.get(position).getIcon());
        tab.setCompoundDrawablesWithIntrinsicBounds(null, iconDrawable, null, null);
    }

    addTab(position, tab);
}

From source file:net.mypapit.mobile.myrepeater.DisplayMap.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_map);
    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);

    hashMap = new HashMap<Marker, MapInfoObject>();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from   w  ww  .j  a v  a 2 s  . co m*/

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (map == null) {

        // Log.e("Map NULL", "MAP NULL");
        Toast.makeText(this, "Unable to display Map", Toast.LENGTH_SHORT).show();

    } else {

        LatLng latlng = (LatLng) getIntent().getExtras().get("LatLong");

        Repeater xlocation = new Repeater("", new Double[] { latlng.latitude, latlng.longitude });

        rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this);
        xlocation.calcDistanceAll(rl);
        rl.sort();

        map.setMyLocationEnabled(true);
        map.setOnInfoWindowClickListener(this);
        map.getUiSettings().setZoomControlsEnabled(true);

        AdView mAdView = (AdView) findViewById(R.id.adViewMap);
        mAdView.loadAd(new AdRequest.Builder().build());

        // counter i, for mapping marker with integer
        int i = 0;

        for (Repeater repeater : rl) {

            MarkerOptions marking = new MarkerOptions();
            marking.position(new LatLng(repeater.getLatitude(), repeater.getLongitude()));
            marking.title(repeater.getCallsign() + " - " + repeater.getDownlink() + "MHz (" + repeater.getClub()
                    + ")");

            marking.snippet("Tone: " + repeater.getTone() + " Shift: " + repeater.getShift());

            RepeaterMapInfo rmi = new RepeaterMapInfo(repeater);
            rmi.setIndex(i);

            hashMap.put(map.addMarker(marking), rmi);

            i++;

        }

        // Marker RKG = map.addMarker(new MarkerOptions().position(new
        // LatLng(6.1,100.3)).title("9M4RKG"));

        map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 10));
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

        cache = this.getSharedPreferences(CACHE_PREFS, 0);

        Date cachedate = new Date(cache.getLong(CACHE_TIME, new Date(20000).getTime()));

        long secs = (new Date().getTime() - cachedate.getTime()) / 1000;
        long hours = secs / 3600L;
        secs = secs % 3600L;
        long mins = secs / 60L;

        if (mins < 5) {
            String jsoncache = cache.getString(CACHE_JSON, "none");
            if (jsoncache.compareToIgnoreCase("none") == 0) {
                new GetUserInfo(latlng, this).execute();

            } else {

                loadfromCache(jsoncache);
                // Toast.makeText(this, "Loaded from cache: " + mins +
                // " mins", Toast.LENGTH_SHORT).show();
            }

        } else {

            new GetUserInfo(latlng, this).execute();

        }

        map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

            @Override
            public View getInfoWindow(Marker marker) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public View getInfoContents(Marker marker) {
                Context context = getApplicationContext(); // or
                // getActivity(),
                // YourActivity.this,
                // etc.

                LinearLayout info = new LinearLayout(context);
                info.setOrientation(LinearLayout.VERTICAL);

                TextView title = new TextView(context);
                title.setTextColor(Color.BLACK);
                title.setGravity(Gravity.CENTER);
                title.setTypeface(null, Typeface.BOLD);
                title.setText(marker.getTitle());

                TextView snippet = new TextView(context);
                snippet.setTextColor(Color.GRAY);
                snippet.setText(marker.getSnippet());

                info.addView(title);
                info.addView(snippet);

                return info;
            }
        });

    }

}

From source file:edu.cens.loci.ui.widget.GenericEditorView.java

private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) {

    ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>();

    HashMap<String, APInfoMapItem> apMap = wifi.getAps();
    Set<String> keys = apMap.keySet();
    Iterator<String> iter = keys.iterator();
    while (iter.hasNext()) {
        String bssid = iter.next();
        APInfoMapItem ap = apMap.get(bssid);
        items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets));
    }/* w  w  w . j av a 2s .  com*/

    Collections.sort(items);

    table.setColumnCollapsed(0, false);
    table.setColumnCollapsed(1, true);
    table.setColumnShrinkable(0, true);

    for (int i = 0; i < mAddedRows.size(); i++) {
        table.removeView(mAddedRows.get(i));
    }
    mAddedRows.clear();

    int totalCount = wifi.getScanCount();

    Context context = getContext();

    for (WifiViewListItem item : items) {
        TableRow row = new TableRow(context);

        TextView ssidView = new TextView(context);
        ssidView.setText(item.ssid);
        //ssidView.setText("very very very veryvery very very very very very");
        ssidView.setPadding(2, 2, 2, 2);
        ssidView.setTextColor(0xffffffff);

        TextView bssidView = new TextView(context);
        bssidView.setText(item.bssid);
        bssidView.setPadding(2, 2, 2, 2);
        bssidView.setTextColor(0xffffffff);

        TextView cntView = new TextView(context);
        cntView.setText("" + (item.count * 100) / totalCount);
        cntView.setPadding(2, 2, 2, 2);
        cntView.setGravity(Gravity.CENTER);
        cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        TextView rssView = new TextView(context);
        rssView.setText("" + item.rss);
        rssView.setPadding(2, 2, 6, 2);
        rssView.setGravity(Gravity.CENTER);
        rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        row.addView(ssidView, new TableRow.LayoutParams(0));
        row.addView(bssidView, new TableRow.LayoutParams(1));
        row.addView(cntView, new TableRow.LayoutParams(2));
        row.addView(rssView, new TableRow.LayoutParams(3));

        //Log.d(TAG, item.ssid);
        for (int i = 0; i < item.rssBuckets.length; i++) {
            TextView box = new TextView(context);
            box.setText("  ");
            box.setGravity(Gravity.RIGHT);
            box.setPadding(2, 2, 2, 2);
            box.setHeight(15);
            box.setGravity(Gravity.CENTER_VERTICAL);

            float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount());
            //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]);
            int colorValInt = ((int) colorVal) - 1;
            if (colorValInt < 0)
                colorValInt = 0;

            box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan));
            box.setTextColor(0xffffffff);

            row.addView(box, new TableRow.LayoutParams(4 + i));
        }

        row.setGravity(Gravity.CENTER);

        table.addView(row, new TableLayout.LayoutParams());
        table.setColumnStretchable(3, true);
        mAddedRows.add(row);
    }

}

From source file:com.csdn.pagerslidingtabstrip.view.PagerSlidingTabStrip.java

private void addTextTab2(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*w  ww.  j ava 2 s . c  om*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab2(position, tab);
}

From source file:com.gmobi.poponews.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    int px = DipHelper.dip2px(50);

    tab.setHeight(px);// www .j av  a  2  s  .com
    px = DipHelper.dip2px(90);
    tab.setPadding(20, 0, 20, 0);
    tab.setText(title);

    tab.setTextAppearance(this.getContext(), R.style.TabTextStyle);
    tab.setGravity(Gravity.CENTER);
    tab.setShadowLayer((float) 0.01, 0, (float) 1.0, 0xffffff);

    addTab(position, tab);
}