Example usage for android.widget RelativeLayout CENTER_IN_PARENT

List of usage examples for android.widget RelativeLayout CENTER_IN_PARENT

Introduction

In this page you can find the example usage for android.widget RelativeLayout CENTER_IN_PARENT.

Prototype

int CENTER_IN_PARENT

To view the source code for android.widget RelativeLayout CENTER_IN_PARENT.

Click Source Link

Document

Rule that centers the child with respect to the bounds of its RelativeLayout parent.

Usage

From source file:com.google.zxing.client.android.CaptureActivity.java

private void initConView() {
    mToolView = new ViewToolView(this, mData, toolListener);
    RelativeLayout.LayoutParams toolParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);//from w w  w  .j a  va  2 s.c  o m
    int top = (int) getResources().getDimension(EUExUtil.getResDimenID("plugin_uexscanner_tool_top"));
    int left = (int) getResources().getDimension(EUExUtil.getResDimenID("plugin_uexscanner_tool_left"));
    toolParams.setMargins(left, top, left, 0);
    mToolView.setId(1);
    mToolView.setLayoutParams(toolParams);
    mConRel.addView(mToolView);

    viewfinderView = new ViewfinderView(this, mData);
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    viewfinderView.setLayoutParams(viewParams);
    mConRel.addView(viewfinderView);

    mGalleryPic = new ImageView(this);
    RelativeLayout.LayoutParams picParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    picParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    picParams.addRule(RelativeLayout.BELOW, 1);
    picParams.setMargins(left, top, left, top);
    mGalleryPic.setLayoutParams(picParams);
    mConRel.addView(mGalleryPic);

    mGalleryPic.setVisibility(View.GONE);

    mFailText = new TextView(this);
    RelativeLayout.LayoutParams failTextParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    failTextParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mFailText.setLayoutParams(failTextParams);
    mFailText.setGravity(Gravity.CENTER);
    mFailText.setTextColor(Color.WHITE);
    mFailText.setTextSize(25);
    mConRel.addView(mFailText);

    mFailText.setVisibility(View.GONE);
    mFailText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFailText.setVisibility(View.GONE);
            mGalleryPic.setVisibility(View.GONE);
        }
    });

}

From source file:com.goldcard.igas.widget.tabindicator.TabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;//  w w  w  .j  a v a  2  s.  c  o  m
    tabView.setGravity(Gravity.CENTER);
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }
    RelativeLayout rr = new RelativeLayout(this.getContext());
    rr.setGravity(Gravity.CENTER);
    rr.setFocusable(true);
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    tabView.setLayoutParams(lp);
    rr.addView(tabView);
    mTabLayout.addView(rr, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:de.mrapp.android.view.FloatingActionButton.java

/**
 * Inflates the view's layout./*from   ww  w. j a  v a2 s .  c om*/
 */
private void inflateLayout() {
    imageButton = new ImageButton(getContext());
    LayoutParams layoutParams = new LayoutParams(0, 0);
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    addView(imageButton, layoutParams);
}

From source file:justforcommunity.radiocom.adapters.ProgramListAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {

    Article article = articles.get(position);
    if (article != null) {

        if (holder.nameTextView != null) {
            if (article.getTitle() == null) {
                holder.nameTextView.setText("");
            } else {
                holder.nameTextView.setText(article.getTitle());
            }//  w ww.  j  av a 2s . c  o  m
        }

        if (holder.photoImageView != null) {
            if (article.getImage() == null) {
                Picasso.with(mContext).load(R.drawable.logo_nav_header).transform(new CircleTransform())
                        .into(holder.photoImageView);
            } else {
                if (article.getImage().toString() == "") {
                    Picasso.with(mContext).load(R.drawable.logo_nav_header).transform(new CircleTransform())
                            .into(holder.photoImageView);
                } else {
                    Picasso.with(mContext).load(article.getImage()).transform(new CircleTransform())
                            .into(holder.photoImageView);
                }
            }

        }

        if (holder.playView != null && holder.downloadView != null) {
            final File f = new File(
                    GlobalValues.DOWNLOAD_DIR + getFileName(articles.get(position).getEnclosure().getUrl()));

            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.playView
                    .getLayoutParams();

            if (f.exists()) {
                holder.playView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (mActivity.prefs.getString("currentTitlePlaying", "")
                                .equals(articles.get(position).getTitle())) {
                            Intent i = new Intent(mActivity, PodcastingService.class);
                            mActivity.stopService(i);

                            mActivity.edit.putString("currentTitlePlaying", "");
                            mActivity.edit.commit();

                            holder.playView.setBackground(mContext.getResources().getDrawable(R.drawable.play));
                            holder.downloadView
                                    .setBackground(mContext.getResources().getDrawable(R.drawable.download));//play
                            holder.nameTextView.setTextColor(Color.BLACK);
                        } else {

                            Intent localIntent2 = new Intent(mActivity, PodcastingService.class);
                            localIntent2.putExtra("audio", f.toString());
                            localIntent2.putExtra("text", getDate(articles.get(position).getDate()));
                            localIntent2.putExtra("title", articles.get(position).getTitle());
                            mActivity.startService(localIntent2);

                            mActivity.edit.putString("currentTitlePlaying", articles.get(position).getTitle());
                            mActivity.edit.commit();

                            holder.playView
                                    .setBackground(mContext.getResources().getDrawable(R.drawable.stopcolored));//stop
                            holder.downloadView.setBackground(
                                    mContext.getResources().getDrawable(R.drawable.downloadcolored));
                            holder.nameTextView
                                    .setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
                        }
                        notifyDataSetChanged();

                    }
                });
                //take off download
                holder.downloadView.setVisibility(View.GONE);
                layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
                holder.playView.setLayoutParams(layoutParams);

            } else {
                layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 0);
                holder.playView.setLayoutParams(layoutParams);

                holder.playView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (mActivity.prefs.getString("currentTitlePlaying", "")
                                .equals(articles.get(position).getTitle())) {
                            Intent i = new Intent(mActivity, PodcastingService.class);
                            mActivity.stopService(i);

                            mActivity.edit.putString("currentTitlePlaying", "");
                            mActivity.edit.commit();

                            holder.playView.setBackground(mContext.getResources().getDrawable(R.drawable.play));
                            holder.downloadView
                                    .setBackground(mContext.getResources().getDrawable(R.drawable.download));//play
                            holder.nameTextView.setTextColor(Color.BLACK);
                        } else {
                            Intent localIntent2 = new Intent(mActivity, PodcastingService.class);
                            localIntent2.putExtra("audio", articles.get(position).getEnclosure().getUrl());
                            localIntent2.putExtra("text", getDate(articles.get(position).getDate()));
                            localIntent2.putExtra("title", articles.get(position).getTitle());
                            mActivity.startService(localIntent2);

                            mActivity.edit.putString("currentTitlePlaying", articles.get(position).getTitle());
                            mActivity.edit.commit();

                            holder.playView
                                    .setBackground(mContext.getResources().getDrawable(R.drawable.stopcolored));//stop
                            holder.downloadView.setBackground(
                                    mContext.getResources().getDrawable(R.drawable.downloadcolored));
                            holder.nameTextView
                                    .setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                        }
                        notifyDataSetChanged();
                    }
                });
                holder.downloadView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        holder.downloadView.setVisibility(View.INVISIBLE);
                        holder.avi.setVisibility(View.VISIBLE);
                        holder.avi.show();
                        //launch task
                        TaskHelper.execute(new DownloadEpisode(holder.downloadView, holder.avi, mActivity,
                                mContext, articles.get(position).getTitle(),
                                articles.get(position).getEnclosure().getUrl(),
                                getFileName(articles.get(position).getEnclosure().getUrl())));
                    }
                });
            }
        }

        //default paint
        if (mActivity.prefs.getString("currentTitlePlaying", "").equals(articles.get(position).getTitle())) {
            holder.playView.setBackground(mContext.getResources().getDrawable(R.drawable.stopcolored));
            holder.downloadView.setBackground(mContext.getResources().getDrawable(R.drawable.downloadcolored));//stop
            holder.nameTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
        } else {
            holder.playView.setBackground(mContext.getResources().getDrawable(R.drawable.play));
            holder.downloadView.setBackground(mContext.getResources().getDrawable(R.drawable.download));//play
            holder.nameTextView.setTextColor(Color.BLACK);
        }
        holder.itemView.setTag(article);
    }
}

From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java

private void initTitleCenterLayout(LayoutInflater inflater) {
    RelativeLayout vg = (RelativeLayout) titleLayout;
    int titleCenter = getTitleCenterLayoutId();
    if (titleCenter > 0) {
        titleCenterView = inflater.inflate(titleCenter, rootLayout, false);
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        vg.addView(titleCenterView, params);
    }//from   w ww  .  j  av a 2s.  co  m
}

From source file:com.noriginmedia.exoplayer.VideoPlayerFragment.java

private void resizeVideo(Configuration config, boolean fullscreen, int screenWidth, int screenHeight,
        boolean isPortrait, boolean softkeys) {
    if (mView == null || mPlayerView == null)
        return;/*w w  w .  jav  a 2s  .com*/

    int displayWidth = screenWidth;
    int displayHeight = screenHeight;
    int videoWidth = 0;
    int videoHeight = 0;
    int left = 0;
    int top = 0;

    videoWidth = displayWidth;
    videoHeight = displayHeight;

    Log.d(LOG_TAG, "_-_ resizingVideo... vH:" + videoHeight + " vW:" + videoWidth + " mLastH:"
            + mLastVideoHeight + " mLastW:" + mLastVideoWidth);
    int vTop, vLeft;

    if (videoWidth > 0 && videoHeight > 0 && !fullscreen) {
        if (displayHeight - videoHeight > 0) {
            vTop = top + (displayHeight - videoHeight) / 2;
        } else {
            vTop = top;
        }

        if (displayWidth - videoWidth > 0) {
            vLeft = left + (displayWidth - videoWidth) / 2;
        } else {
            vLeft = left;
        }
    } else {
        vTop = 0;
        vLeft = 0;
    }

    if (mLastVideoWidth != videoWidth || mLastVideoHeight != videoHeight || vTop != mLastTop
            || vLeft != mLastLeft) {
        RelativeLayout.LayoutParams paramsV;

        if (videoWidth > 0 && videoHeight > 0) {
            paramsV = new RelativeLayout.LayoutParams(videoWidth, videoHeight);
            paramsV.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            paramsV.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        } else {
            paramsV = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
                    RelativeLayout.LayoutParams.FILL_PARENT);
            paramsV.addRule(RelativeLayout.CENTER_IN_PARENT);
        }
        mLastTop = paramsV.topMargin = vTop;
        mLastLeft = paramsV.leftMargin = vLeft;
        Log.d(LOG_TAG, "_-_ resizedVideo tm:" + paramsV.topMargin + " tl: " + paramsV.leftMargin + " w:"
                + paramsV.width + " h:" + paramsV.height + " fullscreen:" + fullscreen);

        mPlayerView.setLayoutParams(paramsV);
        mView.requestLayout();

        mLastVideoHeight = videoHeight;
        mLastVideoWidth = videoWidth;
    }

    boolean fullView = (displayWidth >= screenWidth && displayHeight >= screenHeight);
}

From source file:io.imoji.sdk.grid.ui.ResultView.java

public void loadSticker() {
    int width = getDimension(0);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, width);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    imageView.setLayoutParams(params);//from  w w  w  .j ava 2s.c  o  m

    textView.setVisibility(GONE);
    startResultAnimation();
}

From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java

public void initialization(final boolean landscape, final boolean openAD, final Location lad,
        final String publisherId, final String keywords, final int requestInterval) {
    if (openAD) {
        // setVolumeControlStream(AudioManager.STREAM_MUSIC);
        AdManager.setPublisherId(publisherId);
        AdManager.setTestDevices(new String[] { "" });
        AdManager.setAllowUseOfLocation(true);
        view = new LGameAndroid2DView(LGameAndroid2DActivity.this, landscape);
        IHandler handler = view.getGameHandler();
        RelativeLayout mainLayout = new RelativeLayout(LGameAndroid2DActivity.this);
        RelativeLayout.LayoutParams mainParams = new RelativeLayout.LayoutParams(handler.getWidth(),
                handler.getHeight());//from   w  w  w  .j av a2s.  c om
        if (landscape) {
            mainParams.addRule(RelativeLayout.CENTER_HORIZONTAL, 1);
        } else {
            mainParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1);
        }
        mainLayout.addView(view, mainParams);

        adview = new AdView(LGameAndroid2DActivity.this);
        if (keywords != null) {
            adview.setKeywords(keywords);
        }
        adview.setRequestInterval(requestInterval);
        adview.setGravity(Gravity.NO_GRAVITY);
        RelativeLayout rl = new RelativeLayout(LGameAndroid2DActivity.this);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        if (lad == Location.LEFT) {
            lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 1);
        } else if (lad == Location.RIGHT) {
            lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 1);
        } else if (lad == Location.TOP) {
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1);
        } else {
            lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);
        }
        // adview.setVisibility(View.GONE);

        visible = true;
        frameLayout.addView(mainLayout);
        rl.addView(adview, lp);
        frameLayout.addView(rl);
    } else {
        view = new LGameAndroid2DView(LGameAndroid2DActivity.this, landscape);
        IHandler handler = view.getGameHandler();
        RelativeLayout mainLayout = new RelativeLayout(LGameAndroid2DActivity.this);
        RelativeLayout.LayoutParams mainParams = new RelativeLayout.LayoutParams(handler.getWidth(),
                handler.getHeight());
        if (landscape) {
            mainParams.addRule(RelativeLayout.CENTER_HORIZONTAL, 1);
        } else {
            mainParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1);
        }
        mainLayout.addView(view, mainParams);
        frameLayout.addView(mainLayout);
    }
    if (setupSensors) {
        // ??
        this.initSensors();
    }
    if (view != null) {
        gameHandler = view.getGameHandler();
    }
}

From source file:com.adwhirl.AdWhirlLayout.java

public void pushSubView(ViewGroup subView) {
    RelativeLayout superView = superViewReference.get();
    if (superView == null) {
        return;//from www .  jav  a  2 s . c  o  m
    }
    superView.removeAllViews();

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    superView.addView(subView, layoutParams);

    Log.d(AdWhirlUtil.ADWHIRL, "Added subview");

    this.activeRation = nextRation;
    countImpression();
}

From source file:com.derrick.movies.MovieDetailsActivity.java

private void setTrailers(Videos videos) {
    videosList = videos.getResults();/*from  www.ja  v a 2s . c  om*/
    int size = videosList.size();
    if (size == 1) {
        txt_title_trailer.setText("Trailer");
    }

    for (int i = 0; i < size; i++) {

        Result result = videosList.get(i);
        String url = IMAGE_YOUTUBE + result.getKey() + YOUTUBE_QUALITY;
        ImageView imageView;
        ImageView imageView_play;
        TextView txt_name;

        ViewGroup.LayoutParams lp = new RelativeLayout.LayoutParams(70, 70);
        ViewGroup.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);

        RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT));

        if (size == 1) {
            imageView = new ImageView(getApplicationContext());
            imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        } else {
            imageView = new ImageView(getApplicationContext());
            imageView
                    .setLayoutParams(new RelativeLayout.LayoutParams(500, ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }

        imageView_play = new ImageView(getApplicationContext());
        imageView_play.setLayoutParams(lp);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView_play
                .getLayoutParams();
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        imageView_play.setLayoutParams(layoutParams);
        imageView_play.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Drawable drawable = getResources()
                .getDrawable(getResources().getIdentifier("play", "drawable", getPackageName()));
        imageView_play.setImageDrawable(drawable);

        txt_name = new TextView(getApplicationContext());
        txt_name.setLayoutParams(lp2);
        RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) txt_name.getLayoutParams();
        layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        layoutParams2.setMargins(8, 8, 8, 16);
        txt_name.setLayoutParams(layoutParams2);
        txt_name.setTypeface(robotoCondensed);
        txt_name.setText(result.getName());
        txt_name.setTextColor(getResources().getColor(R.color.colorWhite));

        Glide.with(getBaseContext()).load(url).diskCacheStrategy(DiskCacheStrategy.ALL)
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

                        return false;
                    }
                }).into(imageView);

        // trailerSlider.addView(imageView_play);
        relativeLayout.addView(imageView);
        relativeLayout.addView(imageView_play);
        relativeLayout.addView(txt_name);
        trailerSlider.addView(relativeLayout);

    }

}