Change content and layout inside another layout
I have lot of stories but a fixed number, for example 20, of different stories not connected.
I need to implement in Android something like div
on the center of the screen and inside that div
(100% width and height of the div) I put some content (only one story at a time, but with different layouts: some have pictures, some are splitted and so on).
I just need advices on how to implement this. Do I need to put every story in a different frameLayout
with only one visible at the moment (ever开发者_运维技巧y story frameLayout
is inside div's Frame Layout) or is there any good way to load content in one div's layout from separated xml files?
There are differnet options.
The one you thought about: a FrameLayout with every item's visibility set to INVISIBLE except the one shown.
Use LinearLayout, but in stead of INVISIBLE, use GONE. This way the layout's size will be calculated only based on the visible layout.
Add and remove the content on demand: use LayoutInflater to "load" the view that the user wants to see.
ViewGroup container; // The container that you want to fill with dynamic content
changeLayout(int layoutId) {
container.removeAllViews();
getLayoutInflater(layoutId, container);
}
精彩评论