2014-05-22 34 views
2

我有一個Rss源應用程序,顯示xml中的標題和說明。我解析XML並在webview中顯示內容。當我導航到webview時,我無法滾動內容。這就像靜態。有沒有辦法在webview內滾動內容?如何在Google Glass中滾動webview

的WebView:

title = (TextView) findViewById(R.id.title); 
     desc = (WebView) findViewById(R.id.desc); 

     // set webview properties 
     WebSettings ws = desc.getSettings(); 
     ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 
     ws.getPluginState(); 
     ws.setPluginState(PluginState.ON); 
     ws.setJavaScriptEnabled(true); 
     ws.setBuiltInZoomControls(true); 

     // Set the views 
     title.setText(feed.getItem(pos).getTitle()); 

     desc.loadDataWithBaseURL("http://www.googleglass.gs/", feed 
       .getItem(pos).getDescription(), "text/html", "UTF-8", null); 

解析:

public class DOMParser { 

    private RSSFeed _feed = new RSSFeed(); 

    public RSSFeed parseXml(String xml) { 

     URL url = null; 
     try { 
      url = new URL(xml); 
     } catch (MalformedURLException e1) { 
      e1.printStackTrace(); 
     } 

     try { 
      // Create required instances 
      DocumentBuilderFactory dbf; 
      dbf = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder db = dbf.newDocumentBuilder(); 

      // Parse the xml 
      Document doc = db.parse(new InputSource(url.openStream())); 
      doc.getDocumentElement().normalize(); 

      // Get all <item> tags. 
      NodeList nl = doc.getElementsByTagName("item"); 
      int length = nl.getLength(); 

      for (int i = 0; i < length; i++) { 
       Node currentNode = nl.item(i); 
       RSSItem _item = new RSSItem(); 

       NodeList nchild = currentNode.getChildNodes(); 
       int clength = nchild.getLength(); 

       // Get the required elements from each Item 
       for (int j = 1; j < clength; j = j + 2) { 

        Node thisNode = nchild.item(j); 
        String theString = null; 
        String nodeName = thisNode.getNodeName(); 

        theString = nchild.item(j).getFirstChild().getNodeValue(); 

        if (theString != null) { 
         if ("title".equals(nodeName)) { 
          // Node name is equals to 'title' so set the Node 
          // value to the Title in the RSSItem. 
          _item.setTitle(theString); 
         } 

         else if ("content:encoded".equals(nodeName)) { 
          _item.setDescription(theString); 

          // Parse the html description to get the image url 
          String html = theString; 
          org.jsoup.nodes.Document docHtml = Jsoup 
            .parse(html); 
          Elements imgEle = docHtml.select("img"); 
          _item.setImage(imgEle.attr("src")); 
         } 

         else if ("pubDate".equals(nodeName)) { 

          // We replace the plus and zero's in the date with 
          // empty string 
          String formatedDate = theString.replace(" +0000", 
            ""); 
          _item.setDate(formatedDate); 
         } 

        } 
       } 

       // add item to the list 
       _feed.addItem(_item); 
      } 

     } catch (Exception e) { 
     } 

     // Return the final feed once all the Items are added to the RSSFeed 
     // Object(_feed). 
     return _feed; 
    } 

} 
+0

此問題已被其他貢獻者解決了ListView問題,您是否嘗試過修改此代碼:https://github.com/pscholl/glass_snippets/tree/master/imu_scrollview –

+0

這是針對ListView的。但我要求webview – user3602987

回答

2

你必須實現自己的WebView,並實現該功能,或者您可以使用本機谷歌眼鏡web瀏覽器與意圖。

編輯:您也可以嘗試使用本地web瀏覽器,意圖:

Intent intent = new Intent(Intent.ACTION_VIEW); 
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString()); 
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 
intent.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity"); 
intent.setDataAndType(Uri.fromFile(file),mimetype); 
startActivity(intent); 

你創建你的XML內容的HTML文件,將它保存在SD卡,然後你故意打開。

+0

我看到了示例代碼Mark Scheel給出的。有ListView實現頭部移動。那麼,我應該在這裏爲webView實現嗎? – user3602987

+1

您可以使用該解決方案,但是如果頁面太長,您必須考慮您的脖子會發生什麼情況!我會嘗試實施與本機Web瀏覽器類似的操作,並向左/右滑動頁面滾動頁面 – Bae

+0

用2天拍攝。我無法找到解決方案。我的網頁現在是靜態的。我還沒有在谷歌玻璃做任何行動 – user3602987