我有一个ImageView,我想在我的基本ImageView上绘制另一张图片。
例如,在这个图像中,我有一棵树,我想画出人们的形象。
有什么建议可以开始吗?

是的,我的问题是:“Tsunaze说:
我有一棵树,我想把头放在上面,
发布于 2013-12-31 16:28:03
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_tree"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:src="@drawable/my_tree" />
</RelativeLayout>MyView.java:
public MyView extends View{
private Bitmap head_1, head_2;
public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
init();
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init();
}
public MyView(Context context) {
super(context);
this.context = context;
init();
}
private void init(){
head_1= BitmapFactory.decodeResource(context.getResources(),
R.drawable.head_1);
head_2= BitmapFactory.decodeResource(context.getResources(),
R.drawable.head_2);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(head_1, coordinateX_head_1, coordinateY_head_1, null);
canvas.drawBitmap(head_2, coordinateX_head_2, coordinateY_head_2, null);
}
}选择所需的坐标,甚至可以使用像canvas.getWidth()或canvas.getHeight()这样的函数。装作画家。祝好运。
发布于 2013-12-31 15:18:10
setBackgroundResource到ImageView并对其使用setImageResource。
Ex :
imageView.setBackgroundResource(R.id.backgroundTree);
imageView.setImageResource(R.id.allPeople);编辑:
如果希望覆盖多个图像,则看看这个例子。
您还可以通过编程方式使用RelativeLayout并在其中添加ImageView。
<RelativeLayout>
<ImageView/>
<ImageView/>
<ImageView/>
<ImageView/>
</RelativeLayout>发布于 2013-12-31 15:22:57
您需要做的是创建一个从ImageView扩展而来的类,像往常一样设置您想要的默认参数,并重写overlay方法,这个方法将给您提供一个对画布的引用,并绘制位图或几乎任何您想要的东西,但请记住首先调用super.onDraw以保持默认配置并覆盖新图像。
关于如何使用画布有很多教程,所以现在您可以选择正确的路径,希望这会有所帮助。
问候
https://stackoverflow.com/questions/20859233
复制相似问题