Android viewpager未显示完整页面

时间:2014-10-27 09:24:05

标签: android-viewpager

我在scrollview中使用ViewPager。我无法查看我的ViewPager页面底部视图。我甚至尝试为scrollview,viewpager甚至我的viewpager的第一个孩子设置固定高度,但它们都没有工作。![在此处输入图像描述] [1]

这是我在小屏幕模拟器和设备上获得的:

我将以下代码用于我的questions.xml:

<RelativeLayout
        android:id="@+id/parentOfScroll"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white"
        android:layout_above="@+id/categoryBottomLayout"
        android:layout_below="@+id/titleLayout" >

        <com.pk.base.CustomScrollView
            android:id="@+id/customScrollView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true" >

            <com.pk.adapter.MyCustomViewPager
                android:id="@+id/questionViewPager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:paddingLeft="15dp"
                android:paddingRight="15dp" />
        </com.pk.base.CustomScrollView>
    </RelativeLayout>

和我的page.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="300dp">
    <!-- <TextView android:id="@+id/textMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" /> -->
    <TextView android:id="@+id/questionTitleTextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:text="@string/default_question_title"
        />
    <TextView android:id="@+id/questionTextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/default_question"
        android:layout_below="@+id/questionTitleTextView"
        />
    <TextView android:id="@+id/answerTitleTextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:text="@string/default_answer_title"
        android:layout_below="@+id/questionTextView"
        />
    <TextView android:id="@+id/answer1TextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/default_answer1"
        android:layout_below="@+id/answerTitleTextView"
        />
    <TextView android:id="@+id/answer2TextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/default_answer2"
        android:layout_below="@+id/answer1TextView"
        />
    <TextView android:id="@+id/answer3TextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/default_answer3"
        android:layout_below="@+id/answer2TextView"
        />
    <TextView android:id="@+id/answer4TextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/default_answer4"
        android:layout_below="@+id/answer3TextView"
        />
    <!-- <TextView android:id="@+id/answer5TextView"
        android:textColor="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/default_answer5"
        android:layout_below="@+id/answer4TextView"
        /> -->

</RelativeLayout>

和我的CustomViewPager:

public class MyCustomViewPager extends ViewPager {

    public MyCustomViewPager(Context context) {
        super(context);

    }

    public MyCustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int height = 0;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            child.measure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            int h = child.getMeasuredHeight();
            if (h > height)
                height = h;
        }

        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
                MeasureSpec.AT_MOST);

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

主要问题是当我向下滚动页面时,我无法在ViewPager中看到我的页面的底部文本。请帮忙。

0 个答案:

没有答案