How to inflate a activity in my case?

2019-07-13 12:45发布

问题:

I would like to achieve this layout :

my main activity layout (main.xml);

(Please mouse right click the following image and view image)

I have made another ContentActivity (with content set to content_one.xml) which is supposed to be used as part (the right part) of the above layout:

I know I can inflate a layout by:

LinearLayout mainLayout =  (LinearLayout) findViewById(R.id.main);

LayoutInflater inflater = (LayoutInflater)Home2.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = (View) inflater.inflate(R.layout.content_one, null);

mainLayout.addView(inflatedView);

I am wondering, besides inflate the content_one layout into main layout, is it possible to inflate a activity class instead of inflating a layout in android? If possible, how to do it?

回答1:

You cant inflate an Activity as such. Consider using Fragments.

http://developer.android.com/guide/topics/fundamentals/fragments.html