2010-06-17 39 views
6

我已經在XML定義的列表視圖如下如何改變佈局餘量爲Android的ListView控件編程

 <ListView android:id="@+id/mylist" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:cacheColorHint="#00000000" 
      android:layout_weight="1" 
      android:layout_marginTop="95dip"/> 

,我需要在我的長期計劃重新定義後的一些結果佈局保證金,我怎麼可以實現這一點

回答

23

更簡單地說,你可以修改現有的MarginLayoutParams實例修改保證金:直接

ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) mListView 
     .getLayoutParams(); 

mlp.setMargins(adjustmentPxs, 0, 0, 0); 

break; 
+0

您還可以設置特定的邊距用這種方式(即mlp.leftMargin = 8)。 – Jason 2017-11-22 18:25:35