我在我的android布局中有一个ImageView
。我想在图像视图的右下角添加一个“修饰器”图像。 你能告诉我我该怎么做?如何在我的图像视图顶部添加装饰图像
我正在考虑使用带有2个图像视图的FramLayout作为其子视图,但是如何使一个图像在另一个图像的右下角?
<FrameLayout>
<ImageView .../>
<ImageView .../>
</FrameLayout>
我在我的android布局中有一个ImageView
。我想在图像视图的右下角添加一个“修饰器”图像。 你能告诉我我该怎么做?如何在我的图像视图顶部添加装饰图像
我正在考虑使用带有2个图像视图的FramLayout作为其子视图,但是如何使一个图像在另一个图像的右下角?
<FrameLayout>
<ImageView .../>
<ImageView .../>
</FrameLayout>
你可能想而不是使用RelativeLayout
(Documentation) - 它支持堆叠的景致,所有你需要做的是对齐的底部和离开覆盖ImageView
与底部和左侧的。
您可以创建自己的扩展ImageView的类。它将始终在ImageView内容上绘制装饰器。
public class MyImage extends ImageView {
static Bitmap decorator;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(decorator==null)
decorator = BitmapFactory.decodeResource(getResources(), R.drawable.decorator);
canvas.drawBitmap(decorator, 0, 0, null);
}
public MyImage(Context context) {
super(context);
}
public MyImage(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
public MyImage(Context context, AttributeSet attrs, int params) {
super(context, attrs, params);
}
}
因此,这是更好的方法或创建自己的ImageView? – michael 2010-07-30 18:42:51
这取决于你想要做什么。 Fedor描述的方法稍微有些资源友好和可扩展性,所以如果你要这样做数以百计的图像或者你可能想要他的方法。我描述的方法在XML和基本布局代码中更容易实现。 – QRohlf 2010-07-30 18:51:40