Android draw border in ImageView

后端 未结 2 1477
面向向阳花
面向向阳花 2020-12-17 00:36

I want to draw a border around an image. But I can\'t align the border at the ImageView itself (like it is done mostly) because I translate and scale the image inside of the

2条回答
  •  猫巷女王i
    2020-12-17 01:08

    Alternatively, put the imageView in a layout of some sort and just set padding:

    static class BorderView extends FrameLayout
        {
            public ImageView imageView;
    
            public BorderView(Context context)
            {
                super(context);
    
                setLayoutParams(//wrap content)
                imageView = new ImageView(context);//set image and so forth
                addView(imageView);
            }
    
            public void addSelectionBorder()
            {
                int border = 8;
                setPadding(border,border,border,border);
                setBackgroundColor(Color.BLUE);
            }
    
            public void removeSelectionBorder()
            {
                int border = 0;
                setPadding(border,border,border,border);
                setBackgroundColor(Color.BLACK);
            }
        }
    

提交回复
热议问题