我有一些ImageView's
,使用ImageLoader
或类似技术绕过角落似乎太麻烦了。
我可以简单地制作LinearLayout
来覆盖图片吗? (或将图像设置为背景?)例如,如果布局有圆角,是否会隐藏图像下方的部分以创建圆角效果?
我一直试图玩这个(特别是使用图像作为背景)并且似乎无法隐藏图像的角落。
答案 0 :(得分:1)
好吧,使用FrameLayout或RelativeLayout,您可以轻松地在imageview上堆叠第二层,如:
<FrameLayout
android:layout_width="60dp"
android:layout_width="60dp">
<ImageView android:id="@+id/myimage"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/myrealimage" />
<ImageView android:id="@+id/my_roundedcorner_overlay"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/myoverlaywithroundedcornersandtransparentcenter" />
</FrameLayout>
然而,请注意这会导致过度绘制并使您的布局更复杂。
你也可以将真实图像设置为ImageView的背景,将叠加层设置为ImageViews src,但是在这种情况下不设置填充(也可以使用库加载来自Web的图像可能不再有效) )
最干净的解决方案是创建一个扩展ImageView并覆盖其onDraw方法的自定义窗口小部件,使用bitmapshader绘制到画布,类似于http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/几乎相同,但是只需执行一次并根据需要重复使用
答案 1 :(得分:0)
我曾遇到过同样的问题,只有我想创建一个带圆角的Google地图,请检查一下 问题:
Is there a way to implement rounded corners to a Mapfragment?
诀窍是创建一个FrameLayout
并在其中放置内容,并在其上放置另一个带有圆角的9-patch
图像背景的布局。
答案 2 :(得分:0)
如果您使用Universal Image Loader,则可以改为覆盖图像的角落。
DisplayImageOptions options = new DisplayImageOptions.Builder()
.displayer(new RoundedBitmapDisplayer())
.build();
ImageLoader.getInstance().displayImage(imageUrl, imageView, options);