可能这是一个非常愚蠢的问题,但我创建了这样的结构,但我确实遇到了性能问题。
public class OuterClass extends LinearLayout {
private LinearLayout viewPort;
public OuterClass(Context context) {
super(context);
initComponents(context);
addInnerClass();
}
private void initComponents(Context context){
LayoutInflater inflater = (LayoutInflater) getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.view_port, this);
viewPort = (LinearLayout) findViewById(R.id.view_port);
}
private void addInnerClass(){
for ( int i = 0; i < k; i++ ){
InnerClass functio = this.new InnerClass();
viewPort.addView(functio);
}
}
private class InnerClass extends RelativeLayout{
private LineraLayout newLines;
public InnerClass() {
super(OuterClass.this.context);
initComponents(OuterClass.this.context);
addNLines();
}
private void initComponents(Context context){
LayoutInflater inflater = (LayoutInflater) getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.job_function_container, this);
newLines = (LinearLayout) findViewById(R.id.newLines);
}
private void addInnerOfInner(View view){
newLines.addView(view);
}
private void addNLines(){
for ( int i = 0; i < k1; i++ ){
InnerOfInnerClass line = this.new InnerOfInnerClass();
addInnerOfInner(line);
}
}
public class InnerOfInnerClass extends RelativeLayout{
private InnerOfInnerClass(){
super(OuterClass.this.context);
initComponents(OuterClass.this.context);
}
private void initComponents(Context context){
LayoutInflater inflater = (LayoutInflater) getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.new_line, this);
// Setting some fields.
}
}
}
}
更具体地说,如果我尝试在每个 InnerClass 中创建 5 个 InnerClass 对象和 5 个 InnerOfInner Class 对象,那真的很慢。如果有人能解释一下原因,我将不胜感激。谢谢。