Jump to content

Comment scroller un layout sans le XML?


DevAndroid

Recommended Posts

Euh ok ...

mais le probleme c'est que je ne sais pas comment faire ce n'est pas un probleme de reproduction.

voila mon layout en Java avec un bouton:

TableLayout continu = new TableLayout (this);
               continu.setOrientation(TableLayout.VERTICAL);    

               Button bouton1 = new Button (this);
               continu.addView(bouton1);
               setContentView(continu);
               bouton1.setOnClickListener(new View.OnClickListener() {
               public void onClick(View view) {
               Intent intent = new Intent (continu.this, enigmes.class);
               startActivity(intent); 
                }
                });

Je voudrais qu'il soit scrollable verticalement.

merci

Link to comment
Share on other sites

Comme sa:

TableLayout continu = new TableLayout (this);
               continu.setOrientation(TableLayout.VERTICAL);

               ScrollView scroll = new ScrollView(this);
               continu.addView(scroll);
               setContentView(continu);

               Button bouton1 = new Button (this);
               continu.addView(bouton1);
               setContentView(continu);
               bouton1.setText("");
               bouton1.setVisibility(bouton1.GONE);
               bouton1.setOnClickListener(new View.OnClickListener() {
               public void onClick(View view) {
               Intent intent = new Intent (continu.this, enigmes.class);
               startActivity(intent); 
                }
                });

Ca ne marche pas

Link to comment
Share on other sites

Pour se servir de ScrollView on met les Layout dedans, pas l'inverse ;)


   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       TableLayout table = new TableLayout(this);
       ScrollView scroll = new ScrollView(this);

       for(int i = 0 ; i < 100 ; i++){
           TextView tv = new TextView(this);
           tv.setText("Bonsoir ! " + i);
           table.addView(tv);
       }

       scroll.addView(table);

       setContentView(scroll);

   }

PS : je crois que l'utilisation des XML est conseillée dans la mesure du possible :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...