android - How To Display Border To Imageview? -
friends how display border imageview ?
i want result mobile gallery image display border.
plz give me ans advance....
you can create resource (layer drawable xml) imageview
's "border" (actually background), , declare in theme
imageview
's background resource drawable xml.
if need "border" changed based on imageview
's state (focused
, selected
, etc.), should create more layer drawables, , put them selector xml (state drawable).
in theme should set imageview
's background selector.xml
.
update
below sample of how specify simple border images, result in
you have
- create new layer drawable file (
image_border.xml
), - modify/create
styles.xml
file - modify/create
colors.xml
file - modify layout xml file (or code) apply style
imageview
.
res/drawable/image_border.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <gradient android:angle="90" android:startcolor="@color/image_border_start" android:centercolor="@color/image_border_center" android:endcolor="@color/image_border_end" /> </shape> </item> <item android:top="2dp" android:left="2dp" android:right="2dp" android:bottom="2dp"> <shape android:shape="rectangle"> <solid android:color="@color/default_back_color" /> </shape> </item> </layer-list>
res/values/styles.xml
add following lines:
<style name="myimageview"> <!-- 3dp background border visible --> <item name="android:padding">3dp</item> <item name="android:background">@drawable/image_border</item> <item name="android:scaletype">fitcenter</item> </style>
res/values/colors.xml
add following lines:
<color name="image_border_start">#40990000</color> <color name="image_border_end">#ff660000</color> <color name="image_border_center">#ffff3333</color>
and specify style of imageview
in layout xml:
<imageview android:id="@+id/my_image" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/efteling" style="@style/myimageview" />
Comments
Post a Comment