2013-05-08 58 views
2

我想:的WebView滾動型阻止所有滾動

  1. 把屏幕上的一個片段,包含:
    1. 一個的WebView
    2. ...完全展開高度
    3. 嵌入一個固定大小的佈局
    4. 滾動佈局(即整個東西,包括全高的webview)

這似乎是不可能的。我現在已經閱讀了10多個關於SO的不同問題/答案,它們都涵蓋了Android WebView中的不同關鍵錯誤,但沒有一個涉及這種情況。

看來(從閱讀其他問題,並按照對Android網站鏈接到當前未修正的錯誤)說:

  1. 的WebView高度一直是錯的(非固定Android的2 - 4:如高度從未減少)
  2. WebView的滾動中斷,不間斷,在連續的Android版本中以新的方式重新打破(例如:某些版本的ScrollView需要控制,其他WebView需要控制,其他版本的WebView需要控制,其他版本會「戰鬥」並且會出現口吃等)
  3. 你必須使用ScrollView的一些奇怪的調整,使它做它應該做的t - out-t他盒。例如「android:fillViewport =」true「(呵呵?是不是應該做什麼」layout_height = fill_parent「)

有沒有人有工作代碼來實現這個相對簡單和通用的設置? d對任何有用的東西都很感興趣(除了當然「扔掉你的Android應用程序並寫一個web應用程序」。這可能會起作用,但不切實際,可悲)

僅供參考(以及任何其他嘗試類似的東西的人)這是我的佈局,填滿屏幕,但所有滾動被禁用,沒有理由,我可以看到:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <!-- page header --> 

     <RelativeLayout 
      android:id="@+id/fragment_detailspage_titletext_layout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:clickable="true" 
      android:visibility="visible" > 

      <include 
       android:id="@+id/fragment_detailspage_titletext_include" 
       layout="@layout/include_textheader" 
       android:visibility="visible" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/fragment_detailspage_header_layout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/fragment_detailspage_titletext_layout" 
      android:clickable="true" 
      android:visibility="visible" > 

      <!-- logo image --> 

      <include 
       android:id="@+id/fragment_detailspage_logoimageheader_include" 
       layout="@layout/include_logoimageheader" /> 
     </RelativeLayout> 

     <!-- page footer --> 

     <RelativeLayout 
      android:id="@+id/fragment_detailspage_footer_layout" 
      android:layout_width="fill_parent" 
      android:layout_height="64dp" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/generic_button_not_pressed" 
      android:clickable="true" 
      android:visibility="visible" > 

      <!-- 1 buttons --> 

      <include 
       android:id="@+id/fragment_detailspage_bottombuttonstrip1_include" 
       android:layout_width="wrap_content" 
       android:layout_height="64dp" 
       android:layout_centerHorizontal="true" 
       layout="@layout/include_bottombuttonstrip1" /> 
     </RelativeLayout> 

     <!-- page content --> 

     <WebView 
      android:id="@+id/fragment_detailspage_content_web" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@id/fragment_detailspage_footer_layout" 
      android:layout_below="@id/fragment_detailspage_header_layout" 
      android:visibility="visible" /> 

    </RelativeLayout> 

</ScrollView> 
+1

你看過這篇文章嗎? http://stackoverflow.com/a/13353874/801437 – 2013-05-08 20:23:49

+0

「我現在已經閱讀了超過10個不同的關於SO的問題/答案,它們都涵蓋了Android WebView中的不同關鍵錯誤,但沒有一個覆蓋這種情況」我很確定我已經回答了很多Android問題,表示將可滾動內容放入ScrollView中很少有效。 – CommonsWare 2013-05-08 20:26:28

+1

對CommonsWare的觀點來說,不要在ScrollView中放置可滾動的視圖。你的佈局看起來可能有些過度設計。你可以附加一個圖像到你想要你的佈局看起來像什麼樣的問題然後,也許我們可以幫助你簡化你的XML並解釋爲什麼你不需要在ScrollView中的WebView – Blundell 2013-05-08 20:46:59

回答

5

對不起,下面的圖片,但我想象它每次,當有人想把滾動視圖滾動視圖內。

enter image description here

請儘量使用CustomScrollView並覆蓋onInterceptTouchEvent

public class CustomScrollView extends ScrollView { 

    public CustomScrollView(Context context) { 
     super(context); 
    } 

    public CustomScrollView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent e) { 
     super.onInterceptTouchEvent(e); 
     return false; 
    } 


} 
+0

+1。 – ademar111190 2014-05-20 22:11:42

1

幾乎老應用程序,我使用了某種形式的Web /卷軸/自定義頁眉/頁腳組合

請注意,「Web」可以是TextView而不是WebView,請記住,「滾動」可以是ListView而不是ScrollView,並且請記住,可以在WebView以內的HTML中實現「自定義頁眉/頁腳組合」。其中任何一種都可以讓您擺脫WebView -in-a-ScrollView方案。幾乎沒有應用程序會使用ScrollView,而更少的應用程序仍會嘗試WebViewScrollView

當然有更復雜的可能性。例如,Gmail的對話視圖是WebView,其他東西使用FrameLayout在Z軸上分層,其中他們可能跟蹤WebView的滾動事件以更改其頂層之上的其他東西的位置(例如,釘住當您滾動到頂部時,發件人和回覆按鈕標題)。

歡迎您使用uiautomatorviewer瞭解如何實現這類功能,如果您有Android 4.1+設備。這就是我看到Gmail如何脫穎而出的原因。你不能得到所有的細節,但它會給你線索。