首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >NestedScrollView和WebView高度问题

NestedScrollView和WebView高度问题
EN

Stack Overflow用户
提问于 2015-06-04 19:49:58
回答 6查看 17.2K关注 0票数 19

我使用新的android.support.v4.widget.NestedScrollView,我遇到了问题。

这是我的布局:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7">

             <!-- some views inside -->

        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"
            />

    </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >

    <WebView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</android.support.v4.widget.NestedScrollView>

我需要在textView中加载html,所以我做了:

content.setText(Html.fromHtml(htmlString));

它看起来很奇怪。我的文本视图放在屏幕的底部。

在我滑动文本后,它开始看起来很正常。

我认为textview并不是唯一有这些问题的视图。我试过使用webview,但它甚至不能显示内容(我想是因为高度计算不正确)。所以我需要网页视图或文本视图来纠正与NestedScrollView的工作。

附注:如果我在dp中设置文本视图高度,那么文本看起来是正确的,但我需要wrap_content作为高度。

更新08.07.15

最后,我需要使用WebView。Alex Facciorusso的回答部分有效,但我面临着另一个问题。当WebView内容有特定的高度时,我可以看到部分内容,但不能向下滚动。示例:

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2015-08-23 16:27:51

正如Mayur Raiyani所说:这个问题在支持库版本22.2.1:code.google.com/p/android/issues/detail?id=175234中得到了解决。感谢所有人的回答。

票数 1
EN

Stack Overflow用户

发布于 2018-10-25 15:15:42

阅读了很多帖子,以及WebView的自定义实现,但我热衷于尝试属性,并找到适合我的方法,如下所示:

对于NestedScrollView使用属性

android:fillViewport="true"

对于底层的WebView,请确保使用高度作为包装

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</WebView>

所以作为伪代码,你有

<NestedScrollView> // height=  match_parent

 <Parent_layout>//could be Realtive/Linear with height= match_parent
   <Some_View></Some_View>
   <Some_View></Some_View>

   <WebView></WebView> // height=  wrap_content
 </Parent_layout>

</NestedScrollView>
票数 5
EN

Stack Overflow用户

发布于 2015-06-06 22:10:55

一个简单的解决方法是在LinearLayout内部添加一个500dp高度低于TextView的空视图。这个视图将把你的TextView推到正确的位置。

<android.support.v4.widget.NestedScrollView
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<!-- Your scrolling content -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/random_text" />

    <View
        android:layout_width="match_parent"
        android:layout_height="500dp"/>


</LinearLayout>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30643081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档