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....
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.
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!
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With