Example usage for android.view Gravity CENTER

List of usage examples for android.view Gravity CENTER

Introduction

In this page you can find the example usage for android.view Gravity CENTER.

Prototype

int CENTER

To view the source code for android.view Gravity CENTER.

Click Source Link

Document

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

Usage

From source file:com.astuetz.PagerSlidingTabStripWithStyle.java

private void addTextTab(final int position, String title) {
    RadioButton tab = new RadioButton(getContext());
    tab.setButtonDrawable(android.R.color.transparent);
    tab.setBackgroundDrawable(null);/*w  ww .j  a  v  a2 s. c  o  m*/
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:ch.hackzurich.migrozept.ScanditSDKSampleBarcodeActivity.java

/** 
 *  Called when a barcode has been decoded successfully.
 *  /* ww w  .  j a  v a2 s .c  o m*/
 *  @param barcode Scanned barcode content.
 *  @param symbology Scanned barcode symbology.
 */
public void didScanBarcode(String barcode, String symbology) {
    // Remove non-relevant characters that might be displayed as rectangles
    // on some devices. Be aware that you normally do not need to do this.
    // Only special GS1 code formats contain such characters.
    String cleanedBarcode = "";
    for (int i = 0; i < barcode.length(); i++) {
        if (barcode.charAt(i) > 30) {
            cleanedBarcode += barcode.charAt(i);
        }
    }

    Log.i("custom", "Send Barcode to API " + cleanedBarcode);

    String url = "http://hackzurich14.herokuapp.com/api/" + cleanedBarcode + "?recipes=1";
    try {
        new APIWorker(this).execute(new URL(url));
    } catch (Exception e) {
        //showAlert("Exception",e.toString());
        showToast("API Worker call Exception");
    }

    mButton = new Button(this);
    mButton.setTextColor(Color.WHITE);
    mButton.setTextSize(30);
    mButton.setGravity(Gravity.CENTER);
    mButton.setBackgroundColor(0xFF000000);
    mButton.setText("Scanned " + symbology + " code:\n\n" + cleanedBarcode + "\n");
    ((RelativeLayout) mBarcodePicker).addView(mButton, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mBarcodePicker.pauseScanning();

    // TODO: go to recipe overview
    mButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBarcodePicker.resumeScanning();
            ((RelativeLayout) mBarcodePicker).removeView(mButton);
            mButton = null;
        }
    });
    mButton.requestFocus();

    // Example code that would typically be used in a real-world app using 
    // the Scandit SDK.
    /*
    // Access the image in which the bar code has been recognized.
    byte[] imageDataNV21Encoded = barcodePicker.getCameraPreviewImageOfFirstBarcodeRecognition();
    int imageWidth = barcodePicker.getCameraPreviewImageWidth();
    int imageHeight = barcodePicker.getCameraPreviewImageHeight();
            
    // Stop recognition to save resources.
    mBarcodePicker.stopScanning();
    */
}

From source file:com.sina.android.weibo.sdk.widget.LoginoutButton.java

/**
 * ??/*from w  w  w  .  j  a  v a2 s .  c om*/
 * 
 * @param attrs XML ?
 */
private void loadDefaultStyle(AttributeSet attrs) {
    if (attrs != null && 0 == attrs.getStyleAttribute()) {
        Resources res = getResources();
        this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
        this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
        this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
        this.setCompoundDrawablePadding(
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_with_weibo_account);
    }
}

From source file:aierjun.com.aierjunlibrary.widget.tablayout.PagerSlidingTabStrip.java

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

    TextView tab = new TextView(getContext());
    tab.setText(title);//from   www. j av a2 s . c  o  m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    addTab(position, tab);
}

From source file:android.improving.utils.views.PagerSlidingTabStrip.java

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

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

From source file:com.android.yijiang.kzx.widget.PagerSlidingTabStrip.java

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

    TextView tab = new TextView(getContext(), null, android.R.attr.textAppearanceMedium);
    tab.setText(title);/*from   www .  j  a v a 2  s.  co m*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:com.astuetz.PagerSlidingTitleIconTabStrip.java

private void addTextIconTab(final int position, String title, int resId) {

    if (resId == TitleIconTabProvider.NONE_ICON) {
        addTextTab(position, title);//from   w  w  w. j  av  a 2s .c om
        return;
    }

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    ImageView icon = new ImageView(getContext());
    icon.setImageResource(resId);

    LinearLayout linearLayout = new LinearLayout(getContext());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    linearLayout.addView(icon, defaultTabLayoutParams);
    linearLayout.addView(tab, defaultTabLayoutParams);

    addTab(position, linearLayout);
}

From source file:org.quantumbadger.redreader.activities.ImageViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences);

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = General.uriFromString(intent.getDataString());
    final RedditPost src_post = intent.getParcelableExtra("post");

    if (mUrl == null) {
        General.quickToast(this, "Invalid URL. Trying web browser.");
        revertToWeb();//from ww w.  j  av a  2  s .  c  o m
        return;
    }

    Log.i("ImageViewActivity", "Loading URL " + mUrl.toString());

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    CacheManager.getInstance(this)
            .makeRequest(mRequest = new CacheRequest(mUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY,
                    Constants.FileType.IMAGE, false, false, false, this) {

                private void setContentView(View v) {
                    layout.removeAllViews();
                    layout.addView(v);
                    v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                    v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                }

                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(context.getApplicationContext(),
                            new RRError(null, null, t));
                }

                @Override
                protected void onDownloadNecessary() {
                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(true);
                        }
                    });
                }

                @Override
                protected void onDownloadStarted() {
                }

                @Override
                protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status,
                        final String readableMessage) {

                    final RRError error = General.getGeneralErrorForFailure(context, type, t, status,
                            url.toString());

                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {
                            // TODO handle properly
                            mRequest = null;
                            progressBar.setVisibility(View.GONE);
                            layout.addView(new ErrorView(ImageViewActivity.this, error));
                        }
                    });
                }

                @Override
                protected void onProgress(final boolean authorizationInProgress, final long bytesRead,
                        final long totalBytes) {
                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(authorizationInProgress);
                            progressBar.setProgress((int) ((100 * bytesRead) / totalBytes));
                        }
                    });
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, final String mimetype) {

                    if (mimetype == null
                            || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) {
                        revertToWeb();
                        return;
                    }

                    final InputStream cacheFileInputStream;
                    try {
                        cacheFileInputStream = cacheFile.getInputStream();
                    } catch (IOException e) {
                        notifyFailure(RequestFailureType.PARSE, e, null,
                                "Could not read existing cached image.");
                        return;
                    }

                    if (cacheFileInputStream == null) {
                        notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image");
                        return;
                    }

                    if (Constants.Mime.isVideo(mimetype)) {

                        AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                if (mIsDestroyed)
                                    return;
                                mRequest = null;

                                try {
                                    final RelativeLayout layout = new RelativeLayout(context);
                                    layout.setGravity(Gravity.CENTER);

                                    final VideoView videoView = new VideoView(ImageViewActivity.this);

                                    videoView.setVideoURI(cacheFile.getUri());
                                    layout.addView(videoView);
                                    setContentView(layout);

                                    layout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                                    layout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                                    videoView.setLayoutParams(
                                            new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                    ViewGroup.LayoutParams.MATCH_PARENT));

                                    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                                        @Override
                                        public void onPrepared(MediaPlayer mp) {
                                            mp.setLooping(true);
                                            videoView.start();
                                        }
                                    });

                                    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                                        @Override
                                        public boolean onError(final MediaPlayer mediaPlayer, final int i,
                                                final int i1) {
                                            revertToWeb();
                                            return true;
                                        }
                                    });

                                    videoView.setOnTouchListener(new View.OnTouchListener() {
                                        @Override
                                        public boolean onTouch(final View view, final MotionEvent motionEvent) {
                                            finish();
                                            return true;
                                        }
                                    });

                                } catch (OutOfMemoryError e) {
                                    General.quickToast(context, R.string.imageview_oom);
                                    revertToWeb();

                                } catch (Throwable e) {
                                    General.quickToast(context, R.string.imageview_invalid_video);
                                    revertToWeb();
                                }
                            }
                        });

                    } else if (Constants.Mime.isImageGif(mimetype)) {

                        final PrefsUtility.GifViewMode gifViewMode = PrefsUtility
                                .pref_behaviour_gifview_mode(context, sharedPreferences);

                        if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) {
                            revertToWeb();
                            return;

                        } else if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) {
                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                @Override
                                public void run() {
                                    LinkHandler.openWebBrowser(ImageViewActivity.this,
                                            Uri.parse(mUrl.toString()));
                                    finish();
                                }
                            });

                            return;
                        }

                        if (AndroidApi.isIceCreamSandwichOrLater()
                                && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) {

                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                public void run() {

                                    if (mIsDestroyed)
                                        return;
                                    mRequest = null;

                                    try {
                                        final GIFView gifView = new GIFView(ImageViewActivity.this,
                                                cacheFileInputStream);
                                        setContentView(gifView);
                                        gifView.setOnClickListener(new View.OnClickListener() {
                                            public void onClick(View v) {
                                                finish();
                                            }
                                        });

                                    } catch (OutOfMemoryError e) {
                                        General.quickToast(context, R.string.imageview_oom);
                                        revertToWeb();

                                    } catch (Throwable e) {
                                        General.quickToast(context, R.string.imageview_invalid_gif);
                                        revertToWeb();
                                    }
                                }
                            });

                        } else {

                            gifThread = new GifDecoderThread(cacheFileInputStream,
                                    new GifDecoderThread.OnGifLoadedListener() {

                                        public void onGifLoaded() {
                                            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                                                public void run() {

                                                    if (mIsDestroyed)
                                                        return;
                                                    mRequest = null;

                                                    imageView = new ImageView(context);
                                                    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                                    setContentView(imageView);
                                                    gifThread.setView(imageView);

                                                    imageView.setOnClickListener(new View.OnClickListener() {
                                                        public void onClick(View v) {
                                                            finish();
                                                        }
                                                    });
                                                }
                                            });
                                        }

                                        public void onOutOfMemory() {
                                            General.quickToast(context, R.string.imageview_oom);
                                            revertToWeb();
                                        }

                                        public void onGifInvalid() {
                                            General.quickToast(context, R.string.imageview_invalid_gif);
                                            revertToWeb();
                                        }
                                    });

                            gifThread.start();

                        }

                    } else {

                        final ImageTileSource imageTileSource;
                        try {

                            final long bytes = cacheFile.getSize();
                            final byte[] buf = new byte[(int) bytes];

                            try {
                                new DataInputStream(cacheFileInputStream).readFully(buf);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }

                            try {
                                imageTileSource = new ImageTileSourceWholeBitmap(buf);

                            } catch (Throwable t) {
                                Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t);
                                General.quickToast(context, R.string.imageview_decode_failed);
                                revertToWeb();
                                return;
                            }

                        } catch (OutOfMemoryError e) {
                            General.quickToast(context, R.string.imageview_oom);
                            revertToWeb();
                            return;
                        }

                        AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                if (mIsDestroyed)
                                    return;
                                mRequest = null;
                                mImageViewDisplayerManager = new ImageViewDisplayListManager(imageTileSource,
                                        ImageViewActivity.this);
                                surfaceView = new RRGLSurfaceView(ImageViewActivity.this,
                                        mImageViewDisplayerManager);
                                setContentView(surfaceView);

                                surfaceView.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View v) {
                                        finish();
                                    }
                                });

                                if (mIsPaused) {
                                    surfaceView.onPause();
                                } else {
                                    surfaceView.onResume();
                                }
                            }
                        });
                    }
                }
            });

    final RedditPreparedPost post = src_post == null ? null
            : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false,
                    false, RedditAccountManager.getInstance(this).getDefaultAccount(), false);

    final FrameLayout outerFrame = new FrameLayout(this);
    outerFrame.addView(layout);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this,
                new BezelSwipeOverlay.BezelSwipeListener() {

                    public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) {

                        toolbarOverlay.setContents(
                                post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay));
                        toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT
                                ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    }

    setContentView(outerFrame);
}

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url       The url to load.//  w w w.j av  a 2s  . co  m
 * @param jsonObject 
 */
public String showWebPage(final String url, JSONObject options, String myNewTitle) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }
    zeTitle = myNewTitle;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);
                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            edittext = new TextView(ctx.getContext());
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(zeTitle);
            edittext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24);
            edittext.setGravity(Gravity.CENTER);
            edittext.setTextColor(Color.DKGRAY);
            edittext.setTypeface(Typeface.DEFAULT_BOLD);
            edittext.setLayoutParams(editParams);

            webview = new WebView(ctx.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGICHTML")) {
                        String msg = cmsg.message().substring(9); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d(LOG_TAG, "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });

            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new SlaveBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    view.loadUrl(
                            "javascript:console.log('MAGICHTML'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(edittext);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:cn.mailchat.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    //layout//  ww w .  j ava  2s  .  co m
    RelativeLayout tabLayout = new RelativeLayout(getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tabLayout.setLayoutParams(layoutParams);

    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    textParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    //tab
    TextView tab = new TextView(getContext());
    tab.setId(100 + position);
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tabLayout.addView(tab, textParams);

    //???
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId());
    viewParams.addRule(RelativeLayout.CENTER_VERTICAL);
    View view = new View(getContext());
    ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(vParams);
    tabLayout.addView(view, viewParams);

    addTab(position, tabLayout);

}