Created
April 29, 2015 11:15
-
-
Save layerlre/91871aeefa02292cd7e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
v = inflater.inflate(R.layout.xxxx, container, false); | |
gridView = (GridView)v.findViewById(R.id.gridview); | |
gridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
if (gridView.getColumnWidth()>0) { | |
seteGridviewHeight(gridView,จำนวนitem,gridView.getNumColumns()); | |
gridView.getViewTreeObserver().removeOnGlobalLayoutListener(this); | |
} | |
} | |
}); | |
return v; | |
} | |
private void seteGridviewHeight(GridView gridView, float itemCount,float numColumn) { | |
int row = (int) Math.ceil((itemCount + 1f) / numColumn); | |
Log.d("debug", "-------row = " + row); | |
int height = (imageHeight * row); // imageHeight = ความสูงของแต่ละแถวหรือความสูงของรูป | |
height += (row - 1) * verticalSpacing; | |
gridView.getLayoutParams().height = height; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment