I need to center grid view horizontally in my android layout.xml. I have searched google for quite a while but didnt succeed in finding an answer.
I can only change gridview horizontal position by changing strechMode, but then my items are not near one another. that i need is items be one near another (without spaces) and centered horizontally. I choose strechmode = none, so now my items are near one another, but they are on the left of the screen, i just want them to be centered horizontally.
Here is my layout xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:gravity="center">
<GridView android:id="@+id/lw_gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:columnWidth="48dp"
android:horizontalSpacing="0dp"
android:verticalSpacing="0dp"
android:stretchMode="none"
/>
</LinearLayout>
Here is fragment of an image which is set on gridview by image adapter:
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(48,48)); //on medium density
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setPadding(0, 0, 0, 0);
How can i succeed?