0

I have made a transparent custom progress bar.I want to move the progress bar to a certain location on the screen programatically.But every time the custom progress bar get drawn at the middle of the screen.

public class CustomProgressBar extends Dialog {
ProgressBar mProgressBar;
TextView mTextMessage;

public CustomProgressBar(Context context, int id) {
    super(context, R.style.ProgressDialogTheme);
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.custom_progree_dialog,
            null);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);//the progress bar does not get aligned to left top with the defined margin space.
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);//
    params.setMargins(50, 50, 0, 0);//

    // layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, id);

    this.addContentView(view, params);

}

}

And this is how I am using it inside my activity

  Dialog mProgressBar = new CustomProgressBar(
            MyActivity.this,
            otherView.getId());

My progress bar layout file custom_progree_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ProgressBar
    android:id="@+id/id_server_connection_progress_dialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminateDrawable="@drawable/somedrwablefile" />

<TextView
    android:id="@+id/id_server_connection_textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="@dimen/padding_30px"
    android:layout_marginTop="@dimen/padding_4px"
    android:layout_toRightOf="@id/progress_dialog"
    android:text="@string/connectingMessage"
    android:textColor="@color/white"
    android:textSize="@dimen/padding_40px" />

</RelativeLayout>

Please guide me and let me know where I am going wrong.I have spent two days trying to figure out the problem.

luckysing_noobster
  • 1,933
  • 5
  • 24
  • 50
  • The type of LayoutParam relate to the surrounding type of layout. Whats the layout type, the Custom ProgressBar is included in? If it is LinearLayout for example, you must use `LinearLayoutParams` to position your Dialog. – jboi Nov 12 '13 at 23:56
  • The layout type for my activity where I am adding the progress bar is relativelayout. – luckysing_noobster Nov 13 '13 at 00:04
  • Next thing to check: can you post the XML of the surrounding Layout? The ProgressBar should show up on the upper left corner. Where does it get actually places. – jboi Nov 13 '13 at 00:33

1 Answers1

0

So I solved this problem by making changes to my custom_progress_dialog and aligning the progress bar and the text to the location I want.Also I am not using the custom class any more.I am just inflating the layout at runtime and adding it as a child view inside my activity.

   if (mView == null) 
   {
    mView = getLayoutInflater().inflate(R.layout.server_connection_progree_dialog,null);

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
    MyActivity.this.addContentView(mView, layoutParams);
   }
   else 
     if (!mView.isShown()) 
      {
         mView.setVisibility(View.VISIBLE);
      }
luckysing_noobster
  • 1,933
  • 5
  • 24
  • 50