0

I have a gridview of images, i need to add one drawable image as a separator between images in gridview.

anyone help me how to add.?

Vishwanath.M
  • 6,005
  • 9
  • 39
  • 55

1 Answers1

-1

try this hope help

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="@drawable/list_selector">

    <!-- Cell contents -->

</LinearLayout>

list_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_selected="true" 
        android:drawable="@drawable/item_border_selected" 
    />
    <item 
        android:state_pressed="true" 
        android:drawable="@drawable/item_border_selected" 
    />
    <item
        android:drawable="@drawable/item_border" 
    />
</selector>

item_border.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid 
        android:color="@android:color/transparent" 
    />
    <stroke 
        android:width="1px" 
        android:color="@color/list_divider" 
    />
</shape>

item_border_selected.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid 
        android:color="@color/list_select" 
    />
    <stroke 
        android:width="1px" 
        android:color="@color/list_divider" 
    />
</shape>

items_view.xml

<?xml version="1.0" encoding="utf-8"?>
<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="-1px"
    android:layout_marginRight="-1px"
    android:listSelector="@android:color/transparent"
/>

Since all lines double in size as they join their neighboring cells, I made the divider size 1px instead of 1dp so it doesn't appear too large on some screens. Also, I made the grid view have negative margins to hide the lines on either side. I hope this helps someone.from here

Community
  • 1
  • 1
Deepak Swami
  • 3,728
  • 1
  • 27
  • 46
  • I have an image in the drawable folder deepak, i need to add this image as separator between gridview images by setting image width and height to 2dp and 128dp.think your answer is not suitable for my requirement – Vishwanath.M Sep 12 '12 at 04:46
  • See a similar here: http://stackoverflow.com/a/7304166/435605. Both answers are quite similar with a year difference. I wander if it was copied without giving a credit... – AlikElzin-kilaka Oct 29 '12 at 12:23
  • @kilaka hey friend you can see a word from here in end of my answer and also that i have not updated my answer. ok answers are similar but i have already gave credit to original answer.. please check first after comment.. – Deepak Swami Aug 06 '13 at 19:05