2011-09-22 8 views

risposta

5

È possibile aggiungere una vista a un frammento in modo dinamico?

Sì.

Se lo è, come posso farlo?

Allo stesso modo si dovrebbe aggiungere un View altrove: lo chiamano addView() sul contenitore padre s' il View.

+2

Sembra che non ci sia api addView() nella classe Fragment. –

+3

@MS: Ciò è dovuto al fatto che 'Fragment' non è un' ViewGroup' o addirittura un 'View'. Un 'Fragment' potrebbe * contenere * un' ViewGroup'. – CommonsWare

-1
HomeFragment frag = new HomeFragment(); 
FragmentTransaction ft = getFragmentManager().beginTransaction(); 
ft.replace(R.id.fragLogin, frag); 
ft.setCustomAnimations(R.anim.right_in, R.anim.right_out); 
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
ft.commit(); 

Qui, R.id.fragLogin è l'ID del tuo primo frammento che avete dichiarato nella vostra attività xml e HomeFragment è il secondo frammento.

Problemi correlati