1

I try to apply a margin to my elements from BaseAdapter. I tried several things. I'm a bit dissapointed that I cannot just add a margin to my drawable.xml "background".

(Activity - Layout) ItemsView.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.nubage.minepedia.ItemsView">

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="80dp"
        android:gravity="center"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"/>

</RelativeLayout>

(Layout) item_layout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="5dp"
        android:background="@drawable/single_item">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal">
        </ImageView>
        <TextView
            android:id="@+id/lastSyncTextView"
            android:layout_width="70dp"
            android:layout_height="62dp"
            android:textSize="13sp"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal">
        </TextView>

</LinearLayout>

(Drawable) single_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:color="#88000000">
    </solid>
    <stroke
        android:width="2dp"
        android:color="#444444" >
    </stroke>
    <corners
        android:radius="2dp"   >
    </corners>

</shape>

Edit: It looks like this:

enter image description here

I want to separate each "item".

codepleb
  • 10,086
  • 14
  • 69
  • 111

1 Answers1

2

To add padding to drawable you can wrap it in inset.

Bracadabra
  • 3,609
  • 3
  • 26
  • 46