在按钮的单击回调中,创建一个 ImageView 对象,设置瓶子图像,然后对其进行定位。例如(我假设你的元素的名称):
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.beerbottle);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.RelativeLayout01);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.addRule(RelativeLayout.BELOW, R.id.ButtonRecalculate);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
relativeLayout.addView(imageView, layoutParams);
我没有测试过这个,介意你,但它应该给你一个良好的开端。您可能需要将其他参数添加到ImageView,并可能添加到布局参数以使其看起来不错,以及跟踪显示了多少瓶等。