To solve this, add the GridView in a HorizontalScrollView. Then set the fixed height to the GridView inside the HorizontalScrollView. After that, you will be able to dynamically calculate the number of columns of the GridView based on your content and use setNumColumns(int) method to set it.