I am using gridview for displaying group of images from xml using xml parsing, now I want to display the border around each image in gridview. All images should display outline border on image in gridview .how to set border for each image in gridview?
Asked
Active
Viewed 6,500 times
5
-
why don't you set the background in the xml of the grid item. – Sarthak Mittal Aug 16 '15 at 20:43
3 Answers
0
I used this layout in my project you can use this hope it helps.
//Border drawable xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<stroke android:width="0.7dip" android:color="#808080"/>
</shape>
//Layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/grid_selector"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="3dp" >
<ImageView
android:id="@+id/grid_image"
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:contentDescription="@string/gridview_image_desc"
android:scaleType="fitXY" />
</LinearLayout>
<TextView
android:id="@+id/grid_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="6"
android:gravity="center_vertical|center_horizontal"
android:maxLines="3"
android:textColor="#808080"
android:textSize="13sp" >
</TextView>
<TextView
android:id="@+id/grid_text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#ff0000"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>

Surender Kumar
- 1,123
- 8
- 15
0
Did you try setting a resource/color to the imageview's a background on the grid and also specify a padding for for the same?

DeRagan
- 22,827
- 6
- 41
- 50
0
Check this tutorial:
http://www.firstdroid.com/2011/02/06/android-tutorial-gridview-with-icon-and-text/
In the grid.item.xml, and add a background:
If the image size is fixed, add a .png transparent background with border. If the image changes size, you need to use a 9-layer image.
BR, Adrian.

azelez
- 2,501
- 2
- 27
- 26