我使用新的 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 放在屏幕底部。
在我滑动文本后,它开始看起来很正常。
而且我认为 textview 不仅仅是这些问题的 View 。
我尝试使用 webview,但它甚至不显示内容(我认为是由于高度计算不正确)。
所以我需要 webview 或 textview 来纠正 NestedScrollView
的工作。
附:如果我在 dp
中设置 textview 高度,则文本看起来正确,但我需要 wrap_content
作为高度。
08.07.15 更新
最后我需要使用WebView
。 Alex Facciorusso 的回答部分有效,但我遇到了另一个问题。当 WebView
内容具有特定高度时,我可以看到部分内容,但无法向下滚动。
例子:
最佳答案
阅读了很多帖子,也阅读了 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>
关于android - NestedScrollView 和 WebView 高度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30643081/