如何在弹出窗口中显示文本视图底部的按钮?

时间:2015-02-04 12:37:30

标签: android

我可以创建按钮和弹出窗口,但弹出窗口中的按钮会显示在弹出窗口中的文本上方。

我的目的是在弹出窗口中显示弹出窗口底部的那个按钮。

我的代码是:

    public void init() {
    popupButton = (Button) findViewById(R.id.textview1);
    popupText = new WebView(this);
    popupText.setBackgroundResource(R.drawable.first);
    popupText.setBackgroundColor(Color.TRANSPARENT);
    popupText.setVerticalScrollBarEnabled(true);
    popupText.setHorizontalScrollBarEnabled(true);
    insidePopupButton = new Button(this);
    layoutOfPopup = new LinearLayout(this);
    insidePopupButton.setText("log out button");
    insidePopupButton.setBackgroundResource(R.drawable.myborder);
    LayoutParams lpView = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);

    layoutOfPopup.addView(insidePopupButton, lpView);

    String text = "<html><body style=\"text-align:justify\"> %s </body></Html>";
    String summary = "Like 'I am right, you are wrong', dominating or refusing to be dominated, all these games are played by the ego.Very often, we find the inauthentic self is what is at play. </body></html>";
    popupText.loadData(String.format(text, summary), "text/html", "utf-8");
    popupText.setBackgroundResource(R.drawable.first);
    layoutOfPopup.setOrientation(1);
    layoutOfPopup.addView(popupText);
    layoutOfPopup.setBackgroundResource(R.drawable.first);


    public void popupInit() {
    popupButton.setOnClickListener(this);
    insidePopupButton.setOnClickListener(this);
    popupMessage = new PopupWindow(layoutOfPopup, LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    popupMessage.setContentView(layoutOfPopup);

}

输出:

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试按照不同的顺序添加视图:

layoutOfPopup = new LinearLayout(this);
...
layoutOfPopup.addView(popupText);
...
layoutOfPopup.addView(insidePopupButton, lpView);