2010-09-17 2 views

Répondre

7
ListView lst=getListView(); 

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
          LayoutParams.FILL_PARENT, 
          LayoutParams.FILL_PARENT 
         ); 
params.setMargins(0, 0, 0, 0); //left,top,right,bottom 
lst.setLayoutParams(params); 
+0

ou bien (si votre listview est dans un RelativeLayout): RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams (LayoutParams.WRAP_CONTENT, LayoutParams. WRAP_CONTENT); – Hubert

+0

En cas de réglage seulement la marge inférieure que pourrions-nous faire? – ssrp

2

Pour ListView, il y a beaucoup plus de méthode plus simple de changer la marge par Programmatically

ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mListView 
      .getLayoutParams(); 
    layoutParams.setMargins(0, 0, 0, 0); 

Mais pour LinearLayout, vous pouvez définir marge de @UMAR réponse. Amusez-vous. . @ @

0

pour modifier dynamiquement la marge en utilisant l'animation:

Animation animMarginChange = new Animation() { 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
      ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mListView 
      .getLayoutParams(); 
        layoutParams.setMargins(100, 0, 0, 0); 
    } 
}; 
animMarginChange.setDuration(500); // in ms 
mListView.startAnimation(animMarginChange);