【发布时间】:2014-08-20 20:23:44
【问题描述】:
我正在尝试在我的 Android 应用中创建 2D 头像定制器而不使用游戏引擎。
我基本上会以 PNG 图像作为开始的基础。然后我想在基础之上叠加其他图像来自定义角色。
创建这个的最佳选择是什么?我已经创建了一个自定义ImageView 并覆盖了onDraw():
public class AvatarView extends ImageView {
public AvatarView(Context context) {
super(context);
}
public AvatarView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AvatarView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.battle_run_char), 0, 70, null);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.red_cartoon_hat), 70, 0, null);
}
}
通过使用坐标,这似乎非常具体。有没有更好的方法来实现这一点而不必使用坐标?
编辑:
这是我目前所拥有的。这家伙是与红帽子不同的图像。
【问题讨论】:
-
@Rod_Algonquin 已编辑原始帖子。这是我到目前为止所拥有的。在我投入更多精力和时间之前,只是想看看这是否是最好的方法。也在看这个应用程序:androidify.com,但不确定代码有多广泛。
标签: android android-custom-view custom-view avatar