简体   繁体   English

将ScrollView添加到布局后,ViewPager不起作用

[英]ViewPager is not working after adding ScrollView to layout

I added ViewPager () to the layout (root is RelativeLayout) Problem is if I try to keep the root into so that I can slide the screen,but content of Viewpager is not visible, without adding Scrollview it is showing the content. 我将ViewPager()添加到布局中(根目录是RelativeLayout)问题是如果我尝试将根目录保留在其中以便可以滑动屏幕,但是Viewpager的内容不可见,而未添加Scrollview却显示了内容。

My Code activity_profile.xml 我的代码activity_profile.xml

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

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <ImageView
            android:id="@+id/header_imageview"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/header" />

        <LinearLayout
            android:id="@+id/informations_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header_imageview"
            android:gravity="center"
            android:orientation="vertical"
            android:paddingBottom="32dp"
            android:paddingTop="32dp"
            android:weightSum="1">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test Header"
                android:textSize="17dp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:gravity="center"
                android:text="Doctor Certificate"
                android:textColor="#FF707070" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:text="2nd line description"
                android:textColor="#FF909090" />

            <net.thrymr.mednetwork.SlidingTabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="15dp"
                android:layout_height="0dp"
                android:layout_weight="0.20"
                android:background="?attr/colorPrimaryDark" />

        </LinearLayout>


        <ImageView
            android:layout_width="75dp"
            android:layout_height="75dp"
            android:layout_above="@+id/informations_container"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="-16dp"
            android:src="@mipmap/ic_launcher" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/informations_container"
            android:orientation="vertical">


            <net.thrymr.mednetwork.SlidingTabLayout
                android:id="@+id/sliding_tabs_profile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimaryDark" />

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="0px"
                android:layout_weight="0.24"
                android:background="@android:color/white" />

        </LinearLayout>


    </RelativeLayout>
</ScrollView>

ProfileActivty.java ProfileActivty.java

  mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
  mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);

    slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs_profile);
    //  mViewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), titles));
    slidingTabLayout.setViewPager(mViewPager);
    slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.accentColor);
        }
    });

I tried this same thing some time back and had this exact same problem as I remember. 不久前,我尝试过同样的事情,并且遇到了我记得的完全相同的问题。

You need to add android:fillViewport="true" to the ScrollView element and everything will be perfect. 您需要将android:fillViewport="true"ScrollView元素,一切都会变得完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM