create new custom ViewGroup extends FrameLayout
like this :
public class CustomLayout extends FrameLayout {
ProgressBar myProgressBar;
public CustomLayout (Context context) {
super(context);
}
public CustomLayout (Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomLayout (Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void show() {
if (myProgressBar == null) {
addMyProgressBar();
}
myProgressBar.setVisibility(VISIBLE);
}
public void hide() {
if (myProgressBar == null) {
addMyProgressBar();
}
myProgressBar.setVisibility(GONE);
}
private void addMyProgressBar() {
myProgressBar = new ProgressBar(getContext());
LayoutParams params = new LayoutParams(100, 100, Gravity.CENTER);
addView(myProgressBar, params);
}
}
if you want to make ProgressBar always on Top:
- edit
show()
, and hide()
methods.
- add
removeMyProgressBar()
method.
to be like this :
public void show() {
if (myProgressBar == null)
addMyProgressBar();
}
public void hide() {
if (myProgressBar != null)
removeMyProgressBar();
}
private void removeMyProgressBar() {
if (myProgressBar != null) {
removeView(myProgressBar);
myProgressBar = null;
}
}
ActivityBody
is aViewGroup
(customLinearLayout
for example)addView()