我有一个常见的LinearLayout,我想将它放入自己的布局文件中。它将用于包装不同布局文件中的不同视图。是否有可能在Views周围包含一个include(或实现类似的效果)?
答案 0 :(得分:1)
I have a common LinearLayout that I want to put into its own layout file
将LinearLayout
放在单独的布局文件中。膨胀此布局文件:
View mLinearLayoutView = getLayoutInflater().inflate(R.layout.linear_layout, null);
LinearLayout ll = (LinearLayout) mLinearLayoutView.findViewById(R.id.my_linear_layout);
// Inflate the view you want to include within the LinearLayout
View mChildView = getLayoutInflater().inflate(R.layout.any_other_child_view, null);
// Initialize/setup any child components
ll.addView(mChildView); // Or, ll.addView(mChildView, optional_layout_parameters);
setContentView(mLinearLayoutView);