Reputation: 448
I'm having a problems showing items inside a gridview of 2 columns.
The problem, I think, it's related with the recycle process of the views.
The items in my gridview are items with a Text, so the height it's different in every item (depending on the text).
When I make a scroll down or up, sometimes items' height are not well calculated, and some rows are partially overlaping other rows...
What could I do to manage this?
Upvotes: 2
Views: 1365
Reputation: 4511
Here is a working solution: http://obduro.nl/blog/the-solution-of-android-gridview-overlap/
The solution has explained on that link is to calculate each row height based on the height of all its elements (using maximum height).
After testing this, it works beautifully, except for one catch: Once a row size has been increased it will not decrease.
Actual code can be found here: https://github.com/JJdeGroot/AutoGridView
Upvotes: 1
Reputation: 2530
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_icon_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView android:id="@+id/icon_text"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:maxLines="2"
android:singleLine="false"
android:text="Samples Samples"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:typeface="serif" />
</LinearLayout>
Upvotes: 0