2

In my new android app I need to give border to imageview by using something like .9.png.

The border size should change with respect to image which I have given to imageview and If possible I need to give a background image to imageview as I'm going to apply a transparent png image to imageview.

Should I create a new custom view for this?

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
Vishal Vijay
  • 2,518
  • 2
  • 23
  • 45
  • Check this. http://stackoverflow.com/questions/3693234/custom-imageview-with-drop-shadow – Monty Dec 20 '12 at 12:15

1 Answers1

1

I think you should create a custom view. Do a LinearLayout with the background as the border and have the ImageView centered inside the LinearLayout. Use 9-patch to get a correct stretch and create a content area so that the border is showing (use draw9patch in android SDK/Tools).

Example:

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/border">

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />
    </LinearLayout>

Then 9-patch your border (border.9.png in this example). You can have the same stretching as content area.

Heinrisch
  • 5,835
  • 4
  • 33
  • 43
  • k. I will try with this and get back you. – Vishal Vijay Dec 20 '12 at 13:18
  • K I agree with this, I can add border. But I think it won't satisfy the second question. Because I need a master background image. Is it possible adding one more lenier view for background. – Vishal Vijay Dec 20 '12 at 13:28
  • Either your master background is part of the border image or just make the linearlayout to a relative layout and have to images in it. – Heinrisch Dec 20 '12 at 13:35
  • master image is not part of border – Vishal Vijay Dec 20 '12 at 13:39
  • actually my requirement is that. I have circle shape coin image(png transparent image ie, no background ) . I need a border for that. and that coin should have a master background. because it is circle shaped. – Vishal Vijay Dec 20 '12 at 13:45
  • If the border is circular it will be hard, I don't know any convenient way to stretch a circular image. However, if the border is square the solution with relativelayout will work fine. – Heinrisch Dec 20 '12 at 14:27