0

I am trying to add a progressbar(circular spinner) inside a RelativeLayout. The relativeLayout is visible, however the progressbar doesn't show up. Following is the code I am using but it doesn't seem to work.

public class MyCustomView extends RelativeLayout
{

    RelativeLayout rLayout;
    ProgressBar mProgressbar;

    public void init()
    {

        mProgressbar = new ProgressBar(mContext, null, android.R.attr.progressBarStyle);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        mProgressbar.setLayoutParams(params);

        rLayout = new RelativeLayout(mContext);
        rLayout.setBackgroundColor(Color.CYAN);

        rLayout.addView(mProgressbar);
        addView(rLayout);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        if(rLayout != null)
        {
            rLayout.layout(l, t, r, b);
        }
    }

}

What am I doing wrong?

EDIT:

I am trying to add a progressbar(circular spinner) inside a RelativeLayout. The relativeLayout is visible, however the progressbar doesn't show up. Following is the code I am using but it doesn't seem to work.

public class MyCustomView extends RelativeLayout
{
    ProgressBar mProgressbar;

    public void init()
    {

        mProgressbar = new ProgressBar(mContext, null, android.R.attr.progressBarStyle);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        mProgressbar.setLayoutParams(params);

        addView(mProgressbar);
    }

}

Progressbar doesn't even show up now?

My Goals:

  • Showing ProgressBar in the center of the MyCustomView.
user2498079
  • 2,872
  • 8
  • 32
  • 60

0 Answers0