Android如何在Android中的imageview上显示按钮
我想在图像视图中显示图像上方的按钮。有人知道怎么做吗。我是android编程新手Android如何在Android中的imageview上显示按钮,android,image,Android,Image,我想在图像视图中显示图像上方的按钮。有人知道怎么做吗。我是android编程新手 谢谢。使用此按钮,您可以在位图上动态创建按钮 public class MainAct extends GrapActivity implements OnClickListener { private Button saveButton; private Button clearButton; // onCreate Activity protected void onCreate(Bundle saved
谢谢。使用此按钮,您可以在位图上动态创建按钮
public class MainAct extends GrapActivity implements OnClickListener {
private Button saveButton;
private Button clearButton;
// onCreate Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// content view
signature = new MyView(this);
// Dynamically created button on bitmap & canvas
RelativeLayout myLayout = new RelativeLayout(this);
myLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// For Save Button
saveButton = new Button(this);
saveButton.setText("Save");
saveButton.setOnClickListener(this);
// For Clear Button
clearButton = new Button(this);
clearButton.setText("Clear");
clearButton.setOnClickListener(this);
myLayout.addView(signature);
myLayout.addView(saveButton);
myLayout.addView(clearButton);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
//Alignments
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
saveButton.setLayoutParams(params);
//Alignments
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
clearButton.setLayoutParams(params2);
saveButton.bringToFront();
clearButton.bringToFront();
this.setContentView(myLayout);
new Thread(new RefreshRunner()).start();
// onclick listner for CLEAR button
clearButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Activity for Clearing the Screen
startActivity(new Intent(ThisAct.this, ThisAct.class));
finish();
}
});
// onclick listner for SAVE button
saveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//capture the image
try {
saveAsJpg(mBitmap);
startActivity(new Intent(ThisAct.this, MainActivity.class));
finish();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
使用布局容器,例如
FrameLayout
或RelativeLayout
来包含按钮
和图像视图
,并为它们赋予适当的属性,以便它们根据需要重叠