Android:从xml加载布局到新布局

时间:2013-11-22 23:50:17

标签: android android-layout android-linearlayout

我想将xml中的布局加载到新创建的LinearLayout对象中。这可能吗?

LinearLayout new_layout = new LinearLayout(context);
new_layout.load(R.layout.my_layout); // is something like this possible?

1 个答案:

答案 0 :(得分:3)

你想要达到的目的通常是这样做的

LayoutInflater inflater = LayoutInflater.from(context);
LinearLayout newLayout = (LinearLayout) inflater.inflate(R.layout.my_layout, null);
相关问题