Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 嵌套滚动视图中的片段(Viewpager)未加载_Android_Android Fragments_Android Viewpager_Adapter_Android Tablayout - Fatal编程技术网

Android 嵌套滚动视图中的片段(Viewpager)未加载

Android 嵌套滚动视图中的片段(Viewpager)未加载,android,android-fragments,android-viewpager,adapter,android-tablayout,Android,Android Fragments,Android Viewpager,Adapter,Android Tablayout,我的片段布局为CoordinatorLayout,内部为NestedScrollView,内部为NestedScrollView,我的片段布局为ViewPager和TableLayout。选项卡可见,但未加载与选项卡相关的片段 布局 <?xml version="1.0" e

我的片段布局为
CoordinatorLayout
,内部为
NestedScrollView
,内部为NestedScrollView,我的片段布局为
ViewPager
TableLayout
。选项卡可见,但未加载与选项卡相关的片段

布局

                                                                                                            <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:clickable="true"
    android:background="?android:attr/colorBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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


          <android.support.v4.view.ViewPager
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/ViewPagerImages"
              app:layout_collapseMode="parallax"
              app:layout_collapseParallaxMultiplier="0.7"
              android:scrollIndicators="top|right">

          </android.support.v4.view.ViewPager>


            <ProgressBar
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:id="@+id/Progress_Bar_Image"
                android:layout_gravity="center_horizontal|center_vertical"
                android:visibility="visible"
                 />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_gravity="right|top"
                android:layout_marginRight="30dp"
                android:layout_marginTop="30dp"
                android:background="@drawable/round_default"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="25sp"
                    android:text="1"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="25sp"
                        android:text="/5"/>


            </LinearLayout>
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="200dp"
                android:layout_gravity="bottom"
                android:padding="15dp"
                >
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/unsa"
                    android:orientation="horizontal"
                    android:gravity="center">
                    <ImageView
                        android:id="@+id/user_S"
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:padding="10dp" />
                    <TextView
                        android:id="@+id/ViewPager_Name"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="10dp"
                        app:layout_behavior="com.boysjoys.com.pro_working1.CustomClass.UserProfile_Behaviour"
                        android:textSize="35sp" />


                    <TextView
                        android:id="@+id/ViewPager_A"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="10dp"
                        android:text="Age"
                        />

                </LinearLayout>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="New Delhi"
                    android:layout_below="@id/unsa"
                    android:layout_marginLeft="37dp"
                    android:id="@+id/ViewPager_City"
                   />

                <Button
                    android:id="@+id/Attached"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:background="@drawable/round_button"
                    android:layout_alignParentBottom="true"
                    android:elevation="14dp"
                    android:shadowColor="#A8A8A8"
                    android:shadowDx="0"
                    android:shadowDy="0"
                    android:shadowRadius="5"
                    android:text="WRITE ME"
                    android:textColor="#FFFFFF"
                    android:textSize="20sp" />



            </RelativeLayout>


            <View
                android:id="@+id/fabBGLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/custom_transparent_color1"
                android:visibility="gone"/>



            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabOne"
                android:layout_gravity="bottom|end"
                android:padding="12dp"
                android:visibility="gone"
                android:layout_marginBottom="90dp"
                android:layout_marginRight="20dp"
                android:layout_width="45dp"
                android:layout_height="45dp" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabTwo"
                android:padding="12dp"
                app:fabSize="mini"
                android:visibility="gone"
                android:layout_gravity="bottom|end"
                android:layout_marginBottom="90dp"
                android:layout_marginRight="20dp"
                android:layout_width="45dp"
                android:layout_height="45dp" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabThree"
                android:layout_gravity="bottom|end"
                android:padding="12dp"
                app:fabSize="mini"
                android:visibility="gone"
                android:layout_marginBottom="90dp"
                android:layout_marginRight="20dp"
                android:layout_width="45dp"
                android:layout_height="45dp" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabMain"
                android:padding="12dp"
                android:layout_gravity="bottom|end"
                android:layout_marginBottom="90dp"
                android:layout_marginRight="20dp"
                android:src="@drawable/com_facebook_tooltip_black_xout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />


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

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


//            NESTED SCROLL VIEW WHERE THE PROBLEM ARISE
//            TABLAYOUT IS VISIBLE BUT FRAGMENT IS NOT.

    <android.support.v4.widget.NestedScrollView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/userProfile_NestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="13dp"
        android:background="@android:color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">



       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ScrollViewChild"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="15dp">

            <!--To show tab on top of view pager-->
        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabTextColor="@color/place_autocomplete_prediction_primary_text_highlight"
            app:tabSelectedTextColor="@color/colorPrimary"
            app:tabIndicatorColor="@color/colorPrimary"
            android:id="@+id/userProfile_Viewpager_Tab">
        </android.support.design.widget.TabLayout>

            <android.support.v4.view.ViewPager
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/userProfile_Viewpager_Tab"
                android:id="@+id/userProfile_Viewpager_ViewPager">

            </android.support.v4.view.ViewPager>



</RelativeLayout>

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

</android.support.design.widget.CoordinatorLayout>
尝试将片段加载到viewpager中的片段

public class UserProfile_TabAdapter extends FragmentPagerAdapter {
    String TAG = "###TabAdapter###";
    Context context;

    public UserProfile_TabAdapter(FragmentManager fm,Context context) {
        super(fm);
        this.context=context;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        Log.d(TAG," Positions "+position);
        switch (position) {
            case 0:

                fragment = Fragment.instantiate(context,Info_fragment.class.getName());
                break;
            case 1:
                Log.d(TAG, "User Photos Running");
                fragment = Fragment.instantiate(context,Photo_fragment.class.getName());
                break;
            case 2:
                Log.d(TAG, "User Connections Running");
                fragment = Fragment.instantiate(context,Connections_fragment.class.getName());
                break;
        }


        return fragment;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position) {

        switch (position){
            case 0:
                return "About";
            case 1:
                return "Photo";
            case 2:
                return "Connections";

        }
        return null;

    }

}
 //NESTED SCROLL VIEW TAB LAYOUT AND VIEW PAGER
        userInfo_ViewPager=(ViewPager) view.findViewById(R.id.userProfile_Viewpager_ViewPager);
        UserProfile_TabAdapter userProfile_tabAdapter=new UserProfile_TabAdapter(getChildFragmentManager(),getActivity());
        userInfo_ViewPager.setAdapter(userProfile_tabAdapter);
        tabLayout=(TabLayout) view.findViewById(R.id.userProfile_Viewpager_Tab);
        tabLayout.setupWithViewPager(userInfo_ViewPager);
public class Info_fragment extends Fragment {
    public static final String TAG="### INFO ####";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.userprofile_photos,container,false);
        //Above Layout only have colorful background to match parent.
        return view;
    }
}
要加载到viewpager中的片段

public class UserProfile_TabAdapter extends FragmentPagerAdapter {
    String TAG = "###TabAdapter###";
    Context context;

    public UserProfile_TabAdapter(FragmentManager fm,Context context) {
        super(fm);
        this.context=context;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        Log.d(TAG," Positions "+position);
        switch (position) {
            case 0:

                fragment = Fragment.instantiate(context,Info_fragment.class.getName());
                break;
            case 1:
                Log.d(TAG, "User Photos Running");
                fragment = Fragment.instantiate(context,Photo_fragment.class.getName());
                break;
            case 2:
                Log.d(TAG, "User Connections Running");
                fragment = Fragment.instantiate(context,Connections_fragment.class.getName());
                break;
        }


        return fragment;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position) {

        switch (position){
            case 0:
                return "About";
            case 1:
                return "Photo";
            case 2:
                return "Connections";

        }
        return null;

    }

}
 //NESTED SCROLL VIEW TAB LAYOUT AND VIEW PAGER
        userInfo_ViewPager=(ViewPager) view.findViewById(R.id.userProfile_Viewpager_ViewPager);
        UserProfile_TabAdapter userProfile_tabAdapter=new UserProfile_TabAdapter(getChildFragmentManager(),getActivity());
        userInfo_ViewPager.setAdapter(userProfile_tabAdapter);
        tabLayout=(TabLayout) view.findViewById(R.id.userProfile_Viewpager_Tab);
        tabLayout.setupWithViewPager(userInfo_ViewPager);
public class Info_fragment extends Fragment {
    public static final String TAG="### INFO ####";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.userprofile_photos,container,false);
        //Above Layout only have colorful background to match parent.
        return view;
    }
}

//您的appBar布局高度与父项匹配\u使用换行内容更改它

<android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

试试这个

NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.userProfile_NestedScrollView);
scrollView.setFillViewport (true);
问题是您的查看寻呼机高度。只需设置一些高度,您的页面就会显示出来

例如:

          <android.support.v4.view.ViewPager
            android:id="@+id/userProfile_Viewpager_ViewPager"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:layout_below="@id/userProfile_Viewpager_Tab">


        </android.support.v4.view.ViewPager>

您必须找到查看寻呼机未达到高度的原因

NestedScrollView scrollView=(NestedScrollView)findViewById(R.id.userProfile\u NestedScrollView);
scrollView.setFillViewport(true)

我也有同样的问题,最好的解决办法是为您的viewpager设置High

例如:

          <android.support.v4.view.ViewPager
            android:id="@+id/userProfile_Viewpager_ViewPager"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:layout_below="@id/userProfile_Viewpager_Tab">


        </android.support.v4.view.ViewPager>
android:layout\u height=“500dp”

在嵌套滚动视图中添加此行


你为什么不使用
FragmentManager
fragmenttransaction
@heisenberg,因为这对我来说一直都是有效的。我可以在日志中看到片段加载,但没有显示在viewpager@Ritu请在此处添加您的片段布局。@Guruji
@Guruji Its没有任何内容,只是加载了彩色背景。我使用了
wrap\u内容
,然后上面的第一视图页面显示不正确<代码>匹配\u父项在这里为我正确工作有2个视图寻呼机,您指向的是错误的视图寻呼机。看看布局,你会发现第二个我面临的问题让我知道你面临的问题是什么。根据您的问题和代码,2视图寻呼机没有任何关系。你能告诉我为什么
setFillViewport
在我的案例中工作吗?我能避免加载片段直到它打开吗focus@RitusetFillViewport定义滚动视图是否应拉伸其内容以填充视口。您可以从同样在xml视图中工作的android:fillViewport=“true”中找到更多信息