java - prevent gridView from expanding to fit landscape width -
i have gridview 4 columns of imgs. when phone turned landscape layout, grids of gridview expand fill width, creating white spaces in between img although img stay @ desired width. there way keep grid view filling width of screen when in landscape layout ?
i have 2 methods that:
1) create layout each orientation:
res/layout/.... res/layout-land/....
2) 1 layout both vertical , horizontal orientation:
set gridview with:
android:numcolumns="4"
your custom view item, set
android:layout_width="match_parent"
with second method, may encount problem high of item. create custom view , override onmeasure
.
for example: need linearlayout item , keep ratio height/width = 4.5/4
, following custom:
public class mylinearlayout extends linearlayout { //..... constructor methods @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { int scaleheight =(int)( widthmeasurespec/4*4.5); super.onmeasure(widthmeasurespec, scaleheight); } }
Comments
Post a Comment