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:Main.java

public static ProgressBar createProgress(Context context) {
    ProgressBar p = new ProgressBar(context);
    p.setIndeterminate(true);/*w ww .ja  v  a 2  s. co  m*/
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(40, 40);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    p.setLayoutParams(lp);
    return p;
}

From source file:Main.java

public static ProgressBar createProgress(final Context context) {
    final ProgressBar p = new ProgressBar(context);
    p.setIndeterminate(true);/*from ww  w . ja v  a 2 s .  c om*/
    final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(40, 40);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    p.setLayoutParams(lp);
    return p;
}

From source file:me.ziccard.secureit.fragment.EmptyFragment.java

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

    if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
        mContent = savedInstanceState.getString(CONTENT);
    }/*from   w ww.  ja  va2s  . c  o  m*/

    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);

    RelativeLayout layout = new RelativeLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setGravity(Gravity.CENTER);

    RelativeLayout alert = new RelativeLayout(getActivity());
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.leftMargin = 20;
    params.rightMargin = 20;
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    alert.setLayoutParams(params);
    alert.setBackgroundResource(R.drawable.red_back);
    alert.setPadding(30, 0, 30, 0);
    alert.addView(text);
    layout.addView(alert);

    return layout;
}

From source file:Main.java

public static void applyAttributes(JSONObject jsonObject, RelativeLayout.LayoutParams layoutParams)
        throws JSONException {

    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, TO_LEFT_OF, RelativeLayout.LEFT_OF);
    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, TO_RIGHT_OF, RelativeLayout.RIGHT_OF);
    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, BELOW, RelativeLayout.BELOW);
    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ABOVE, RelativeLayout.ABOVE);
    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ALIGN_LEFT, RelativeLayout.ALIGN_LEFT);
    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ALIGN_RIGHT, RelativeLayout.ALIGN_RIGHT);
    applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ALIGN_TOP, RelativeLayout.ALIGN_TOP);

    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_TOP,
            RelativeLayout.ALIGN_PARENT_TOP);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_BOTTOM,
            RelativeLayout.ALIGN_PARENT_BOTTOM);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_RIGHT,
            RelativeLayout.ALIGN_PARENT_RIGHT);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_LEFT,
            RelativeLayout.ALIGN_PARENT_LEFT);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_BASELINE, RelativeLayout.ALIGN_BASELINE);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_TOP,
            RelativeLayout.ALIGN_PARENT_TOP);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, CENTER_HORIZONTAL,
            RelativeLayout.CENTER_HORIZONTAL);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, CENTER_IN_PARENT,
            RelativeLayout.CENTER_IN_PARENT);
    applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, CENTER_VERTICAL,
            RelativeLayout.CENTER_VERTICAL);
}

From source file:com.turingtechnologies.materialscrollbar.Indicator.java

void linkToScrollBar(MaterialScrollBar materialScrollBar) {
    if (Build.VERSION.SDK_INT >= 16) {
        setBackground(ContextCompat.getDrawable(context, R.drawable.indicator));
    } else {//from ww  w  .  j a v  a 2s  .co m
        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.indicator));
    }
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(Utils.getDP(getIndicatorWidth(), this),
            Utils.getDP(getIndicatorHeight(), this));
    lp.setMargins(0, 0, Utils.getDP(8, this), 0);
    setVisibility(INVISIBLE);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getTextSize());
    RelativeLayout.LayoutParams tvlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

    addView(textView, tvlp);

    ((GradientDrawable) getBackground()).setColor(materialScrollBar.handleColour);

    lp.addRule(ALIGN_RIGHT, materialScrollBar.getId());
    ((ViewGroup) materialScrollBar.getParent()).addView(this, lp);
}

From source file:com.github.shareme.gwsmaterialuikit.library.mscrollbar.Indicator.java

void linkToScrollBar(MaterialScrollBar msb, boolean addSpace) {
    this.addSpace = addSpace;
    if (Build.VERSION.SDK_INT >= 16) {
        setBackground(ContextCompat.getDrawable(context, R.drawable.mscrollbar_indicator));
    } else {/*from   w ww.jav  a 2s  .c o m*/
        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.mscrollbar_indicator));
    }
    LayoutParams lp = new LayoutParams(Utils.getDP(getIndicatorWidth(), this),
            Utils.getDP(getIndicatorHeight(), this));
    if (addSpace) {
        lp.setMargins(0, 0, Utils.getDP(15, this) + msb.handle.getWidth(), 0);
    } else {
        lp.setMargins(0, 0, Utils.getDP(2, this) + msb.handle.getWidth(), 0);
    }

    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getTextSize());
    LayoutParams tvlp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

    addView(textView, tvlp);

    ((GradientDrawable) getBackground()).setColor(msb.handleColour);

    lp.addRule(ALIGN_RIGHT, msb.getId());
    ((ViewGroup) msb.getParent()).addView(this, lp);

    materialScrollBar = msb;
}

From source file:com.manning.androidhacks.hack014.MainActivity.java

private void setVideoViewPosition() {
    switch (getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_LANDSCAPE: {
        mPortraitContent.setVisibility(View.GONE);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);

        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        mVideoView.setLayoutParams(params);
        break;//from w  w  w .  j  a v  a  2s .c  o m
    }

    case Configuration.ORIENTATION_SQUARE:
    case Configuration.ORIENTATION_UNDEFINED:
    case Configuration.ORIENTATION_PORTRAIT:
    default: {

        mPortraitContent.setVisibility(View.VISIBLE);

        int[] locationArray = new int[2];
        mPortraitPosition.getLocationOnScreen(locationArray);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mPortraitPosition.getWidth(),
                mPortraitPosition.getHeight());

        params.leftMargin = locationArray[0];
        params.topMargin = locationArray[1];

        mVideoView.setLayoutParams(params);

        break;
    }
    }
}

From source file:org.projectbuendia.client.ui.ProgressFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    mFrame = new RelativeLayout(getActivity());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    mFrame.setLayoutParams(layoutParams);

    RelativeLayout.LayoutParams relativeLayout = new RelativeLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    relativeLayout.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mIndeterminateProgressBar = new ProgressBar(getActivity());
    mIndeterminateProgressBar.setLayoutParams(relativeLayout);

    mProgressBarLayout = inflater.inflate(R.layout.progress_fragment_measured_progress_view, null);
    mProgressBarLayout.setLayoutParams(relativeLayout);
    mProgressBar = (ProgressBar) mProgressBarLayout.findViewById(R.id.progress_fragment_progress_bar);
    mProgressBarLabel = (TextView) mProgressBarLayout.findViewById(R.id.progress_fragment_label);

    RelativeLayout.LayoutParams fullLayout = new RelativeLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    fullLayout.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mErrorTextView = new TextView(getActivity());
    mErrorTextView.setLayoutParams(fullLayout);
    mErrorTextView.setGravity(Gravity.CENTER);

    mContent.setVisibility(View.GONE);
    mProgressBarLayout.setVisibility(View.GONE);
    mFrame.addView(mIndeterminateProgressBar);
    mFrame.addView(mProgressBarLayout);//from www .j  a  v  a  2s  .  c o  m
    mFrame.addView(mContent);
    mFrame.addView(mErrorTextView);
    return mFrame;
}

From source file:com.wms.opensource.images3android.activity.ImageListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (layout != null) {
        ViewGroup parent = (ViewGroup) layout.getParent();
        parent.removeView(layout);/*from w  ww .  j  a va2 s .c  om*/
        return layout;
    }

    if (listView == null) {
        layout = new RelativeLayout(getActivity());
        listView = new ListView(getActivity());
        layout.addView(listView);

        progressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);

        // Center a view in relative layout
        RelativeLayout.LayoutParams progressBarParams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        progressBarParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        progressBar.setLayoutParams(progressBarParams);
        progressBar.setVisibility(View.INVISIBLE);
        layout.addView(progressBar);

        // Before reloading videos, display videos if they have been saved before
        String imagesFilePath = "";
        imagesFilePath = StorageUtil.getTempDirectory(this.getActivity()) + "/"
                + PersistFileNameUtil.getImagesPersistFileName(getString(R.string.imagePlantId), page);

        boolean imagesFileExists = FileUtil.fileExist(imagesFilePath);
        if (imagesFileExists) {
            loadCachedImagesTask = new LoadCachedImagesTask(getActivity(), loadImagesHandler, progressBar,
                    getActivity().getString(R.string.ImageS3ServiceURL),
                    getActivity().getString(R.string.imagePlantId), page);
            loadCachedImagesTask.execute();
        } else {
            NetworkStatus networkStatus = NetworkUtil.getNetworkStatus(getActivity());
            if (networkStatus.equals(NetworkStatus.WIFI_CONNECTED)
                    || networkStatus.equals(NetworkStatus.MOBILE_CONNECTED)) {
                String pageToken = page == 1 ? "" : ImageListFragmentActivity.pageTokens.get(page - 1);
                loadImagesTask = new LoadImagesTask(getActivity(), loadImagesHandler,
                        getActivity().getString(R.string.ImageS3ServiceURL),
                        getActivity().getString(R.string.imagePlantId), pageToken, page);
                loadImagesTask.execute();
            } else {
                Toast.makeText(getActivity(), getString(R.string.noNetworkAvailable), Toast.LENGTH_LONG).show();
            }
        }
    }
    return layout;
}

From source file:klawisch.jimdo.statistics.statisticsdemo.MainActivity.java

private void initProgressBar() {
    layout = (RelativeLayout) findViewById(R.id.relativeLayout);
    customProgressBar = new CustomProgressBar(this);
    customProgressBar.setColor(Color.parseColor("#0097df"));
    customProgressBar.setStrokeWidth(20);
    customProgressBar.setDiameter(500);/*from  w ww.  j  a v  a2 s .c om*/
    //        customProgressBar.setLogProgress(true);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    customProgressBar.setLayoutParams(params);
}