如何在android的弹出窗口中实现垂直滚动?

时间:2015-01-15 17:28:02

标签: android

我尝试了一段代码,但它没有显示垂直滚动条。我的代码粘贴在下面:

     public void init() {
        popupButton = (Button) findViewById(R.id.textview1);
        popupText = new TextView(this);
        insidePopupButton = new Button(this);
        layoutOfPopup = new LinearLayout(this);
        LinearLayout lt=new LinearLayout(this);
        view=new ScrollView(this);
        insidePopupButton.setText("OK");
        popupText.setText("This is Popup Window.press OK to dismiss   it.");
        popupText.setBackgroundColor(Color.WHITE);
        popupText.setPadding(0, 0, 0, 20);
        layoutOfPopup.setOrientation(1);
        lt.addView(popupText);
        layoutOfPopup.addView(insidePopupButton,350,35);

        layoutOfPopup.setBackgroundColor(Color.BLACK);
        view.addView(lt);
        layoutOfPopup.addView(view);

enter image description here 提前谢谢.. :))

2 个答案:

答案 0 :(得分:2)

无论如何,

ScrollView都无法与android中的popupWindow结合使用。伤心但真实。

答案 1 :(得分:-1)

您需要以这种方式添加您的观点:

LinearLayout linearLayout = new LinearLayout(this);

// add all your views to linearLayout(or RelativeLayout)
linearLayout.addView(popupText);
linearLayout.addView(insidePopupButton); 

// add linearLayout to ScrollView instance
view.addView(linearLayout);

// add ScrollView instance to main layout
layoutOfPopup.addView(view);

ScrollView是一个单元素容器。