简体   繁体   中英

Android GridView full screen

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?

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 >

   <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" >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM