设置边框的ImageView的

设置边框的ImageView的

本文介绍了Android的 - 设置边框的ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个固定的宽度和高度的细胞,让它成为100x100px。该小区里面我想显示的的ImageView 带边框。
我的第一个想法是把后台资源的的ImageView ,并添加1DP的填充创建边界的​​效果:

I have a cell with a fixed width and height, let it be 100x100px. Inside that cell I want to display an ImageView with a border around.
My first idea was to put a background resource to the ImageView, and add a padding of 1dp to create the border effect:

<LinearLayout
        android:layout_width="100dp"
        android:layout_height="100dp" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/image_border"
        android:padding="1dp"
        android:src="@drawable/test_image" />

</LinearLayout>

显然,这应该工作,但它没有,或者至少没有达到预期。
的问题是,ImageView的背景填充整个100x100px细胞的空间,从而,如果图像的宽度小于100像素,则顶部和底部边界会出现较大的

Apparently this should work, but it doesn't, or at least not as expected.
The problem is that the ImageView background fills the entire 100x100px cell's space, thus, if the image's width is less than 100px, then the top and bottom border will appear larger.

请注意,黄色边框,我需要它是完全1px的周围ImageView的:

Notice the yellow border, I need it to be exactly 1px around the ImageView:

任何帮助,想法,任何一种建议是非常非常AP preciated。

Any help, idea, suggestion of any kind is much, much appreciated.

推荐答案

如果你把填充= 1和的LinearLayout的背景颜色,你就会有一个1px的黄色边框。

If you put the padding=1 and the background color in the LinearLayout, you'll have a 1px yellow border.

这篇关于Android的 - 设置边框的ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 16:38