简体   繁体   English

在Android中显示的POPUP窗口

[英]POPUP window showing in android

i have created a button in android and when clicking it would show the popup window..but the code doesnot work like that..it has no errors but not showing popup window...please helpme..here is my code public class MainActivity extends Activity { 我在android中创建了一个按钮,单击它会显示弹出窗口..但是代码不能那样工作..它没有错误,但是没有显示弹出窗口...请帮助我..这是我的代码公共类MainActivity扩展活动{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RelativeLayout objrl = (RelativeLayout) findViewById(R.id.myrl);      
    final Button objButton = (Button) findViewById(R.id.mybutton);
    objButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupWindow objPopupWindow = new PopupWindow(objrl, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);                
            objPopupWindow.setAnimationStyle(R.drawable.background2);
            objPopupWindow.showAtLocation(objButton, Gravity.CENTER_HORIZONTAL, 10, 10);
        }
    });

}

have you tried this : objPopupWindow.showAsDropDown(popupButton, 0, 0); 您是否尝试过: objPopupWindow.showAsDropDown(popupButton, 0, 0);

or try this http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html 或尝试使用此http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html

 PopupWindow popupWindowDogs = popupWindowDogs();

called below function where they want ::-





 public PopupWindow popupWindowDogs() {

        // initialize a pop up window type
        PopupWindow popupWindow = new PopupWindow(this);

        // the drop down list is a list view
        ListView listViewDogs = new ListView(this);

        // set our adapter and pass our pop up window contents
        listViewDogs.setAdapter(dogsAdapter(popUpContents));

        // set the item click listener
        listViewDogs.setOnItemClickListener(new DogsDropdownOnItemClickListener());

        // some other visual settings
        popupWindow.setFocusable(true);
        popupWindow.setWidth(250);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

        // set the list view as pop up window content
        popupWindow.setContentView(listViewDogs);

        return popupWindow;
    }

I've found some strange stuff in your codes 我在您的代码中发现了一些奇怪的东西

  • You've specified WRAP_CONTENT but haven't specified its content at all 您已指定WRAP_CONTENT,但完全没有指定其内容
  • Pass a drawable as animation style to the setAnimationStyle method. 将可绘制的动画形式传递给setAnimationStyle方法。

In my opinion if you specify a valid animation style and a content view, It should appear. 我认为,如果您指定有效的动画样式和内容视图,则应显示它。

我认为您在OnClickListener objPopupWindow.setContentView(objrl);错过了此代码objPopupWindow.setContentView(objrl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM