PopupWindow 刻船舰类似对话框风格的窗口
使用PopupWindow 创建对话框风格的串口秩序如下两步即可:
1. PopupWindow 的构造器创建PopupWindow对象
2. PopupWindow 的showAsDropDown() 将其显示效果设置为下拉显示
3. PopupWindow 的showAtLoacation() 方法将PopupWindow() 在指定位置显示出来
具体实现方法:
public class MainActivity extends Activity {
private PopupWindow popupWindow;
private View root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
root = this.getLayoutInflater().inflate(R.layout.cell,null);//add cell.xml above you mainActivity window
popupWindow = new PopupWindow(root,560,700);//create a popupWindow object
root.findViewById(R.id.button01).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//close the popupWindow
popupWindow.dismiss();
}
});
}
public void send(View source){
//set the location of PopupWindow
popupWindow.showAtLocation(findViewById(R.id.send),Gravity.CENTER,20,20);//you can remove this effect
//Use DropDown way to display
popupWindow.showAsDropDown(root);
}
}
mainActivity的布局文件:
/layout/cell.xml