我在我的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