简体   繁体   中英

How to add LinearLayout in other LinearLayout in AndroidStudio

I have two layout.xml like

viewOne.xml and viewTwo.xml

then

How to add viewOne.xml inside the viewTwo.xml programmatically like

viewone.addView(viewTwo);

but it's not working anyway to do this.

programmatically: you can use LayoutInflater

View viewTwo = LayoutInflater.from(context).inflate(R.layout.viewTwo); 
viewOne.addView(viewTwo);
View viewTwo = LayoutInflater.from(context).inflate(R.layout.view_two, viewOne); 

膨胀方法需要2个或更多参数http://developer.android.com/reference/android/view/LayoutInflater.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM