我正在尝试创建一个包含内容区域和进度条的自定义视图,以便任何继承的自定义视图都会在内容区域中对其进行夸大。这样,您可以在子视图上显示/隐藏进度条。
@EViewGroup(R.layout.loading_view)
class LoadingView extends RelativeLayout{
// some code
@ViewById FrameLayout content;
@ViewById ProgressBar pb;
public View getFrameLayout(){
// sub-classes will use this to inject their content
return content;
}
void setIsLoading(boolean l){
// shows\hides pb
}
}
@EViewGroup(R.layout.other_view)
class OtherView extends LoadingView{
@ViewById TextView someTxt;
public OtherView(...){
// inject to getFrameLayout()
}
}
现在这不会远程工作。原因如下:
@EViewGroup
上的 OtherView
会覆盖LoadingView
上的R.layout.loading_view
,因此@EViewGroup(R.layout.loading_view)
甚至无法加载。只有在指定Android Annotations
OtherView
是没有意义的,因为它不会在{{1}}中注入视图。有没有办法让这项工作?有什么想法吗?
答案 0 :(得分:0)
如果我理解正确,你可以解决覆盖方法:
@EViewGroup(R.layout.loading_view)
class LoadingView extends RelativeLayout {
// some code
@ViewById FrameLayout content;
@ViewById ProgressBar pb;
public View getFrameLayout(){
return content;
}
void setIsLoading(boolean l){
// shows\hides pb
}
}
每个孩子都实现了返回其内容的方法:
class OtherView extends LoadingView {
@ViewById TextView someTxt;
@Override
public View getFrameLayout() {
View content = inflate(R.layout.other_view);
return content;
}
}
正如您所说,如果您将@EViewGroup(R.layout.other_view)
放在子类中,AndroidAnnotations将覆盖主布局视图。