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

如何在android中实现弹出窗口的垂直滚动?,android,Android,我尝试了一段代码,但它没有显示垂直滚动条。我的代码粘贴在下面: public void init() { popupButton = (Button) findViewById(R.id.textview1); popupText = new TextView(this); insidePopupButton = new Button(this); layoutOfPopup = new LinearLayout(this

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

     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);

提前感谢您:

您需要以以下方式添加视图:

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是一个单元素容器。

在android中,ScrollView无论如何都不能与popupWindow组合。悲伤但真实

谢谢你,凯尔文瑟。我正在获取滚动条,但关闭弹出窗口的“确定”按钮未显示在弹出窗口上将您的按钮添加到线性布局弹出窗口显示在弹出窗口顶部,而不是在我仅将其添加到主线性布局时显示在下方…我需要在弹出窗口底部显示我的确定按钮..在将视图添加到线性布局时,顺序很重要您必须设计我已经像上面那样更新了我的代码,您能验证一下吗?我已经添加了屏幕截图,但是可以通过调用popupText.setMovementMethodnew ScrollingMovementMethod;激活文本视图的垂直滚动;。不幸的是,我不知道为什么它不能用通常的xml代码工作。。