2015-01-15 60 views
1

我試了一段代碼,但它不顯示垂直滾動條。我的代碼粘貼如下:如何在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 預先感謝您.. :)

回答

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

滾動型是一個單一的元素容器。

+0

謝謝kelvincer。我得到滾動條,但'確定'按鈕關閉彈出窗口不顯示彈出 – Vishwak 2015-01-15 18:28:43

+0

將您的按鈕添加到linearLayout – kelvincer 2015-01-15 18:33:28

+0

按鈕顯示在彈出窗口的頂部,而不是向下當我添加到主要線性佈局只有...我需要在彈出窗口的底部顯示我的Ok按鈕.. – Vishwak 2015-01-15 18:36:53

2

ScrollView無法與android中的popupWindow結合,無論如何。悲傷但真實。

+0

但是可以通過調用 'popupText.setMovementMethod(new ScrollingMovementMethod());'來激活TextViews的垂直滾動。不幸的是,我不知道爲什麼它不能用通常的xml代碼工作。 – 2017-11-02 13:41:21