NestedSCrollView 在 CoordinatorLayout 中没有完全滚动
NestedSCrollView not scrolling fully in CoordinatorLayout
我在CoordinatorLayout
里面有一个NestedSCrollView
。在NestedSCrollView
中有一个ViewPager
。我在其中放置了一个包含 WebView
的片段视图。问题是,如果 WebView
中的文本很长,它就会被剪切,我无法滚动。如何解决?
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nest_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
这是片段xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/appearance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
/>
问题是 ViewPager
不支持 wrap_content
。所以它必须精确或 match parent
。
另一个解决方案是覆盖 ViewPager
的 OnMeasure
方法。看看这个 answer.
我在CoordinatorLayout
里面有一个NestedSCrollView
。在NestedSCrollView
中有一个ViewPager
。我在其中放置了一个包含 WebView
的片段视图。问题是,如果 WebView
中的文本很长,它就会被剪切,我无法滚动。如何解决?
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nest_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
这是片段xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/appearance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
/>
问题是 ViewPager
不支持 wrap_content
。所以它必须精确或 match parent
。
另一个解决方案是覆盖 ViewPager
的 OnMeasure
方法。看看这个 answer.