环绕包括周围的景色

时间:2013-07-25 05:09:16

标签: android android-layout

我有一个常见的LinearLayout,我想将它放入自己的布局文件中。它将用于包装不同布局文件中的不同视图。是否有可能在Views周围包含一个include(或实现类似的效果)?

1 个答案:

答案 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);