2011-03-15 64 views
5

我有这个布局,如果我不在我的Horizo​​ntalScrollView中使用fillviewport = true,它会被奇怪地缩放(可能是由于布局嵌套不可用)。horizo​​ntalscrollview的fillviewport禁用滚动?

当fillviewport = false时,一切都很好用(除了奇数缩放),但是当fillviewport = true时,缩放是完美的,但不会发生滚动。

这是布局(注:我知道你不应该把一个网页视图在一个滚动视图但是WebView中没有一个smoothscrollto也暴露出setscroller方法,所以...的Bleh)

<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/webContainer" 
    android:layout_below="@+id/titlebar" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> 
    <WebView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/webZ" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    /> 
</HorizontalScrollView> 

设置android:fillViewport =“true”通常不会停用视图中的滚动,是吗?

它只是应该确保scrollview填充视口,无论其内容的大小,呃?我认为视口是屏幕的可见区域,并且在web视图中可见区域的边缘处确实存在更多内容,我无法再滚动到该视图。

我可以从logcat看到滚动方法被调用,他们只是不改变屏幕。 (除非我将fillviewport设置为false)

+0

即使你使用的'Horizo​​ntalScrollView'的scrollTo方法,你就不会被滚动'WebView'内容,但'WebView'我自行宣布。我认为你应该警惕在另一方面包装一个。 – 2011-03-15 03:59:16

+1

我想找到另一种方法,但对于我的生活无法使用内置到WebView的方法实现平滑的水平滚动。:( 由于我的项目的重点是显示html,所以实际上没有任何其他视图是有意义的。 – Turnsole 2011-03-15 04:05:30

回答

4

问题是您使用“fill_parent”,这意味着“与我的父母一样大。”改为使用wrap_content代替宽度。

+0

哇,我很尴尬我错过了,但谢谢! – Turnsole 2011-03-15 06:24:21

2

我遇到了一个类似的问题,包含一个WebView的标准ScrollView:滚动不起作用了。将fill_parent更改为wrap_content对我无效。

当扩展视图是TextView但不是被WebView替换时,Romain Guy的示例正常工作。

什么不工作:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:fillViewport="true"> 
    <LinearLayout 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <WebView android:id="@+id/webview" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:layout_weight="1.0"> 
     </WebView> 
     <Button 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:text="Click"> 
     </Button> 
    </LinearLayout>  
</ScrollView> 

当我在web视图数据添加少量它似乎确定:

small_data_not_ok1

但是,当我填写的WebView有很多的数据,它不工作,你可以看到如下:

small_data_not_ok2

该按钮始终显示,滚动不再起作用。事实上,触摸滚动不工作和DPAD滚动运作...

我没有找到任何理由说,但我发现了一个解决方案:它由在加入含有的WebView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:fillViewport="true"> 
    <LinearLayout 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <LinearLayout android:id="@+id/linearlayout" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:layout_weight="1.0" 
      android:orientation="vertical"> 
      <WebView android:id="@+id/webview" 
       android:layout_width="fill_parent" android:layout_height="wrap_content"> 
      </WebView> 
     </LinearLayout> 
     <Button 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:text="Click"> 
     </Button> 
    </LinearLayout>  
</ScrollView> 
一个的LinearLayout

现在它工作正常:

ok1 ok2

相关问题