Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Display Border To Imageview?

Friends How To Display Border To Imageview ?

I Want To Result Like Mobile gallery all image display with border.

plz give me ans thanks for advance....

like image 460
Piyush Avatar asked Apr 30 '11 10:04

Piyush


People also ask

How to give border to Image in android?

When the image is loaded, you will see a scrollable toolbar at the bottom of your screen. There you will find the Border tool. Click on it. This should reveal a new window where you can choose the color and thickness of your border.


2 Answers

I tried all the above solutions but they didn't work for me! So I figured out a simple solution to this! :-)

I remember that I read about FrameLayout of Android in the following article saying that it helps us to stack up our UI elements on top of each other in the same order we add them up.

Solution:

<FrameLayout
    android:layout_width="112dp"
    android:layout_height="112dp"
    android:layout_marginLeft="16dp" <!-- May vary according to your needs -->
    android:layout_marginRight="16dp" <!-- May vary according to your needs -->
    android:layout_centerVertical="true">
    <!-- following imageView acts as the boarder which sitting in the background of our main container ImageView -->
    <ImageView
        android:layout_width="112dp"
        android:layout_height="112dp"
        android:background="#000"/>
    <!-- following imageView holds the image as the container to our image -->
    <!-- layout_margin defines the width of our boarder, here it's 1dp -->
    <ImageView
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:layout_margin="1dp"
        android:id="@+id/itemImageThumbnailImgVw"
        android:src="@drawable/banana"
        android:background="#FFF"/>
</FrameLayout>

Preview:

And that's it. You will get the following like imageView!

preview of the ImageView with boarder

Pros and Cons:

I think this is pretty easy solution to be used in anywhere else and it's all the things you do sits in one single place so easier to modify it. However I don't like to having to add two ImageViews.

like image 187
Randika Vishman Avatar answered Sep 28 '22 06:09

Randika Vishman


You can use this XML file as a drawable instead of multiple files, but this file is placed in drawable folder. In ImageView use this XML file as a background drawable, like: android:background="@drawable/following code file name".

I hope this is helpful for you.

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF" />
    <stroke android:width="1dp" android:color="#000000" />
    <padding android:left="1dp" android:top="1dp" android:right="1dp"
        android:bottom="1dp" />
</shape>
like image 41
Ajit Kumar Dubey Avatar answered Sep 28 '22 06:09

Ajit Kumar Dubey