Reputation: 2243
I have a GridView
and I use BaseAdapter
to adapt images and texts in my GridView
. I have one problem, when I run my app my `GridView' has left, right, top and bottom margins. I do not need these margins.
This is a my xml
source:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/strada_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d6d6d6"
android:gravity="center"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:verticalSpacing="1dp" >
</GridView>
GridView
adapter xml
code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#ffffff" >
<TextView
android:id="@+id/desc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/photo1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-27dp"
android:text="Hello"
android:textColor="#3d3b3b"
android:textSize="12dp" />
<TextView
android:id="@+id/stradaID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/desc1"
android:layout_alignParentBottom="true"
android:text="TextView"
android:textColor="#000000"
android:visibility="gone" />
<ImageView
android:id="@+id/photo1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp" />
</RelativeLayout>
</RelativeLayout>
How I can solve my problem?
Upvotes: 1
Views: 1545
Reputation: 359
I have set the default margin to 0 in the project location /res/values/dimens.xml and it works for me.
< resources >
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
< /resources >
Upvotes: 1
Reputation: 4904
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/strada_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d6d6d6"
android:gravity="center"
android:horizontalSpacing="1dp"
android:numColumns="auto_fit"
android:verticalSpacing="1dp" >
gridview adapter xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
Upvotes: 0