Reputation: 6722
i have simple gridview. it's elements have different height. for example in row there are one small element and one bigger, next row will align to smaller element and a part of bigger element is under the second row. how can i set the height of each row of gridview to be the height of the biggest element in row??
my gridview
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/new_small_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="2"
android:verticalSpacing="3dp"
android:horizontalSpacing="3dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:cacheColorHint="@android:color/transparent"
/>
Upvotes: 4
Views: 7767
Reputation: 3161
For setting cell height, in GridViewAdapter when you write, for example:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
LayoutInflater cellLayout = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = cellLayout.inflate(R.layout.gridcell_layout, null);
}
TextView cell_title = (TextView) convertView.findViewById(R.id.gridview_cell_text);
ImageView cell_icon = (ImageView) convertView.findViewById(R.id.griview_cell_image);
....
Just substitute this line:
convertView = cellLayout.inflate(R.layout.gridcell_layout, null);
With this:
convertView = cellLayout.inflate(R.layout.gridcell_layout, gridView, false);
By this way, setting parent reference in "inflate", Width and Height about cell will set! Here you can find why:
Layout problem with button margin
Upvotes: 4