【发布时间】:2015-06-04 11:49:57
【问题描述】:
我使用新的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 不仅仅是这些问题的视图。
我尝试使用 webview,但它甚至不显示内容(我认为是由于高度计算不正确)。
所以我需要 webview 或 textview 来纠正 NestedScrollView 的工作。
附:如果我在 dp 中设置 textview 高度,那么文本看起来正确,但我需要 wrap_content 的高度。
08.07.15 更新
最后我需要使用WebView。 Alex Facciorusso 的回答部分有效,但我遇到了另一个问题。当WebView 内容具有特定高度时,我可以看到部分内容,但无法向下滚动。
例子:
【问题讨论】:
-
你可以尝试使用 webview 来显示 HTML ..??????
-
@Moinkhan 是的,但是 webview 有另一个问题:它甚至没有出现。而且我的 html 很轻,所以
TextView显示它是正确的。 -
尝试将 LinearLayout 高度作为 match_parent...
-
@Moinkhan 我尝试了很多配置:
LinearLayout设置为match_parent,RelativeLayout与match_parent和wrap_content,将TextView直接放在NestedScrollView中。我认为这是一个NestedScrollView问题,但我不知道出了什么问题。 -
在支持库版本 2.2.1 中解决了这个问题:code.google.com/p/android/issues/detail?id=175234
标签: android android-design-library androiddesignsupport