2015-11-05 3 views
0

Я хочу изменить содержимое «RelativeLayout», проблема в том, что содержимое этого макета находится в другом xml.Загрузить макет из другого XML

setContentView(R.layout.activity_fullscreen); 

//from actual xml 
RelativeLayout rL1= (RelativeLayout) findViewById(R.id.principalLayout); 

//from another xml 
RelativeLayout rL2= (RelativeLayout) findViewById(R.id.cocinaL); 

rL1.removeAllViews(); 
rL1.addView(rL2); //this fail because rL2 is null 

Спасибо

ответ

1

вы не можете добавить еще один макет Посмотреть без LayoutInflater

setContentView(R.layout.activity_fullscreen); 


    //your actule view 
    RelativeLayout rL1= (RelativeLayout) findViewById(R.id.principalLayout); 

    LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
    // your second xml 
    View view2 = inflater.inflate(R.layout.myview12, null); 

    // add second View 
    rL1.addView(view2); 
0

// от фактического XML

RelativeLayout rL1= (RelativeLayout) findViewById(R.id.principalLayout); 

// из другого XML

View child = getLayoutInflater().inflate(R.layout.child, null); 
RelativeLayout rL2 = (RelativeLayout) child.findViewById(R.id.cocinaL); 
rL1.removeAllViews(); 
rL1.addView(rL2); 
Смежные вопросы