2016-09-07 62 views
2

我创建的onClick事件ImageButtonPopupWindow消息PopupWindow消息,我可以看到模拟器的PopupWindow消息,但无法看到它在移动,我已经尝试了许多手机从API 17日至23 。
我无法找到问题无法显示在手机上

@OnClick(R.id.infoRatingDetail) 
public void ratingInfo(View view){ 
    TextView message; 
    PopupWindow popup=new PopupWindow(getContext()); 
    View view_pop=inflater.inflate(R.layout.pop_up_detail,null); 
    message=(TextView)view_pop.findViewById(R.id.pop_up_textView); 
    message.setText(R.string.rating_info); 
    popup.setContentView(view_pop); 
    popup.setOutsideTouchable(true); 
    popup.setFocusable(true); 
    popup.showAsDropDown(view); 
} 

回答

3

我不知道为什么,但我有同样的问题&加入这两行解决了我的问题。

popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); 
popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 
popup.showAsDropDown(view); 
popup.update(); 

希望这对你也有帮助。

+0

它确实解决了我的问题,谢谢 – rookieDeveloper

+0

快乐帮助你:) – buzzingsilently

0

您是否尝试过getApplicationContext()代替getContext()

+0

我正在使用它在一个片段 – rookieDeveloper

+0

所以尝试'getActivity()'获取您的inflater上下文之前? – linhtruong

0

尝试

popup.setWindowLayoutMode(view.LayoutParams.WRAP_CONTENT,view.LayoutParams.WRAP_CONTENT);

+0

setWindowLayoutMode已弃用 – rookieDeveloper

+1

已弃用,但您可以使用'setWidth()'和'setHeight()' – buzzingsilently