简体   繁体   English

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

[英]how to implement vertical scroll on pop-up window in android?

I've tried with a piece of code but it is not displaying vertical scroll bar. 我尝试了一段代码,但是没有显示垂直滚动条。 my code is pasted below: 我的代码粘贴在下面:

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

在此处输入图片说明 Thank you in advance..:) 先感谢您..:)

ScrollView cannot be combine with popupWindow in android, no matter what. popupWindowScrollView都不能与android中的popupWindow结合使用。 Sad but true. 悲伤但真实。

You need to add your views in this way: 您需要通过以下方式添加视图:

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 is a single element container. ScrollView是一个单元素容器。

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

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