在基类中定义了模板窗口,在继承类中通过layout文件修改其中一个窗口的内容。
// 基类layout中定义了一个id为LCD的布局
RelativeLayout mLCD = (RelativeLayout) findViewById(R.id.LCD); // 基类layout中定义了一个id为LCD的布局
// 定义了一个新的nested_layout.xml文件,动态加入到基类的窗口中。
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mNestedLayout = inflater.inflate(R.layout.nested_layout, mLCD);
例如:
public class TestActivity extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
System.out.println(""+this);
// add customize ui elements.
RelativeLayout mLCD = (RelativeLayout) findViewById(R.id.LCD);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mNestedLayout = inflater.inflate(R.layout.nested_layout, mLCD);
}
}