在按钮的点击回调中,创建一个 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 并可能添加到 LayoutParams 以使其看起来不错,并跟踪显示的瓶子数量等。