天天看點

Gridview的stretchMode詳解附自動寬度

2013-03-29 17:01  4390人閱讀  評論(0)  收藏  舉報 [html]  view plain copy

  1. <GridView android:id="@+id/grid"  
  2. android:layout_width="fill_parent"  
  3. android:layout_height="fill_parent"  
  4. android:verticalSpacing="35px" <!-- grid元素之間的豎直間隔 -->  
  5. android:horizontalSpacing="5px" <!--grid元素之間的水準間隔 -->  
  6. android:numColumns="auto_fit" <!--表示有多少列,如果設定為auto_fit,将根據columnWidth和Spacing來自動計算 -->  
  7. android:columnWidth="100px" <!-- 一般建議采用有像素密度無關的dip或者dp來表示-->  
  8. android:stretchMode="columnWidth" <!--如何填滿空餘的位置,模拟器采用WVGA800*480,每排4列,有4*100+5*3=415,還餘65px的空間,如果是columnWidth,則這剩餘的65将分攤給4列,每列增加16/17px。如果采用SpacingWidth,則分攤給3個間隔空隙 -->  
  9. android:gravity="center" />