0

I have a "complex" layout that I want to "move" to a custom component to be able to re-utilize easily but when I do that ProgressBar disappears. I think that the cause could be that the ProgressBar has a custom progressDrawable.

During code execution, progress bar is accessible and visible (well I can't see it, but I check that the visibility property is not the problem...) and there are no errors.

My Custom Layout

        ... 
        </LinearLayout>

    </LinearLayout>

    <!-- Progressbar -->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        >
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="fill_parent"
            android:layout_height="5dp"
            android:id="@+id/progressBar"
            android:progressDrawable="@drawable/customprogressbar"
            android:layout_gravity="center_horizontal"

            />
    </LinearLayout>

</LinearLayout>

My Custom Layout class

public class CustomLayout extends LinearLayout {
    public CustomLayout(Context context) {
        super(context);

    }
    public CustomLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.custom_layout, this, true);
    }
}

My progressDrawable

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
        <shape>
            <gradient
                android:startColor="#000001"
                android:centerColor="#0b131e"
                android:centerY="1.0"
                android:endColor="#0d1522"
                android:angle="270"
                />
        </shape>
    </item>

    <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:startColor="#007A00"
                    android:centerColor="#007A00"
                    android:centerY="1.0"
                    android:endColor="#06101d"
                    android:angle="270"
                    />
            </shape>
        </clip>
    </item>
</layer-list>

My Container Layout Main Activity

<?xml version="1.0" encoding="utf-8"?>

<my.custom.namespace xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

</my.custom.namespace>

My Main Activity

...

setContentView(R.layout.main_activity);

...

mProgressBar = (ProgressBar) findViewById(R.id.progressBar);

// Progress bar is get fine, and I checked that visibility is VISIBLE
//   I didn't change a line of code of this after moving the layout to a custom control
String showProgressbar = sharedPrefs.getString("settings_progressbar_value", Constants.PROGRESSBAR_VISIBLE_BY_DEFAULT);
if (showProgressbar.equals(Constants.PROGRESSBAR_VISIBLE_BY_DEFAULT)) {
    mProgressBar.setVisibility(View.VISIBLE);
} else {
    mProgressBar.setVisibility(View.GONE);
}
rubdottocom
  • 8,110
  • 10
  • 39
  • 59
  • If you place simple View with like red background in place of ProgressBar, do you see it ? – Niko Mar 31 '14 at 08:57
  • Wow, I check that and anything is shown. Finally I play with layout_height property and set the sibling progress bar layout to wrap_content I avoid that this layout take off the screen the progress bar. Thank you! – rubdottocom Mar 31 '14 at 11:43
  • No problem :) Glad you found the problem. – Niko Apr 01 '14 at 03:29
  • Btw the extra LinearLayout which holds the ProgressBar seems to be not needed since it hosts only one child. – Niko Apr 01 '14 at 03:34
  • @Niko, thats true I removed too while I fix the problem, thanks – rubdottocom Apr 01 '14 at 06:41

0 Answers0