1

I want to display progressbar over imageView. Gennerally works nice if i do:

<RelativeLayout
        android:id="@+id/image_holder"
        android:layout_width="120dip"
        android:layout_height="120dip"
        android:layout_gravity="center"
        android:layout_marginLeft="16dip"
        android:layout_marginRight="16dip"
        android:layout_marginTop="22dip" >

        <ImageView
            android:id="@+id/im_photo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop" />

        <ProgressBar
            android:id="@+id/progressbar1"
            android:layout_width="match_parent"
            android:visibility="gone"
            android:layout_height="match_parent" />
    </RelativeLayout>

Is it possible to combine it to single widget?

Yarh
  • 4,459
  • 5
  • 45
  • 95

1 Answers1

0

Yes you can, just make a new class that extends RelativeLayout and inflate it like this:

public class MyView extends RelativeLayout {
    public MyView(Context context) {
        super(context);
        init();
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();

    }

    public MyView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();

    }

    private void init() {
        inflate(getContext(), R.layout.myLayout, this);
        //Create your layout here
    }
}
Squeazer
  • 1,234
  • 1
  • 14
  • 33