Reputation: 868
I want to show images in a two column grid without vertical or horizontal spacing.The images are loaded using Picasso library. This is my code. In most cases it works fine. But in some devices in landscape mode there are spacing between images. How to correct it.
GridView:
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:numColumns="2"
android:id="@+id/movie_grid_view"
/>
image_layout.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/movie_poster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</LinearLayout>
In the cursor adapter:
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.image_layout, parent, false);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView v= (ImageView) view.findViewById(R.id.movie_poster);
Picasso.with(mContext).load(cursor.getString(col_img)).into(v);
}
In landscape mood there are spaces between images
Upvotes: 0
Views: 91
Reputation: 1516
change this in your image_layout.xml
android:scaleType="fitXY" to scale the image
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/movie_poster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</LinearLayout>
hope it helps!!
Upvotes: 2
Reputation: 12861
To solve spacing problem try this Gridview.
GridView:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MyGrid" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:clipChildren="true"
android:alwaysDrawnWithCache="true"
android:numColumns="auto_fit"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:gravity="center_horizontal"
android:background="#000000">
</GridView>
I hope it helps.
Upvotes: 0
Reputation:
Try setting the android margin to 0. Like this:
android:margin="0"
Upvotes: 0