Java Android中滚动视图内的页面视图

Java Android中滚动视图内的页面视图,java,android,fragment,scrollview,Java,Android,Fragment,Scrollview,我有一个android片段布局,我想把我的页面视图放在滚动视图中。当应用程序运行时没有滚动查看它显示的图像,但当我将页面查看代码放入滚动查看中时,它没有显示图像 这是我的密码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="m

我有一个android片段布局,我想把我的页面视图放在滚动视图中。当应用程序运行时没有滚动查看它显示的图像,但当我将页面查看代码放入滚动查看中时,它没有显示图像

这是我的密码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.wk.sigah.FragmentHome"
        android:background="@color/colorPrimary">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v4.view.ViewPager
                android:id="@+id/viewImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </android.support.v4.view.ViewPager>

        </ScrollView>

</LinearLayout>

在类中重写测量上的
onMeasure
,并扩展
ViewPager
,如下所示 将使它达到目前最大的孩子的高度

导入android.content.Context;
导入android.support.v4.view.ViewPager;
导入android.util.AttributeSet;
导入android.view.view;
公共类CustomViewPager扩展了ViewPager{
公共CustomViewPager(上下文){
超级(上下文);
}
公共CustomViewPager(上下文、属性集属性){
超级(上下文,attrs);
}
@凌驾
测量时的保护空隙(内部宽度测量等级、内部高度测量等级){
超级测量(宽度测量、高度测量);
整数高度=0;
对于(int i=0;i高度)高度=h;
}
heightMeasureSpec=MeasureSpec.MakeMasureSpec(高度,精确测量);
超级测量(宽度测量、高度测量);
}
}
在XML中:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:fillViewport="true">

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

    <com.your.package.name.CustomViewPager
        android:id="@+id/viewImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" />

</LinearLayout>

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

为什么需要scrollview?。如果你想让页面滚动,使用scrollview制作您的查看页面的片段xml为什么要将
viewpager
放在
scrollview
中?@JyotiJK我只想将我的页面视图用于顶部的图像滑块,然后在其后面放一些文本我的应用程序:布局\u行为缺失它说的是验证Android xml中的资源尊重files@Kharisma在xml中,您需要替换在java中,您需要声明bby CustomViewPager而不是viewpager。你们做得对吗?是的,当我把app:layout\u行为放在嵌套滚动视图中时,仍然是missing@Kharisma从嵌套的滚动视图中删除它。然后运行代码,让我知道
<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:fillViewport="true">

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

    <com.your.package.name.CustomViewPager
        android:id="@+id/viewImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" />

</LinearLayout>

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