Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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 Viewpager_Height_Expandable - Fatal编程技术网

Android 具有可扩展子级的ViewPager

Android 具有可扩展子级的ViewPager,android,android-viewpager,height,expandable,Android,Android Viewpager,Height,Expandable,我正在尝试创建可折叠日历 我在ViewPager中使用自定义日历视图,所以当按下“展开/折叠”按钮时,我的日历视图将动画化折叠所有日历周(只有一周除外) 目标是在展开时滑动月(我想这样做),在崩溃时滑动周 下面的calendarView是包含一些事件的ListView,当用户折叠日历时,ListView高度必须更改 问题是当我试图在ViewPager中折叠calendarView时,他并没有改变高度 calendarView是带有子视图的线性布局,当它不在ViewPager中时,它会设置动画并更

我正在尝试创建可折叠日历

我在ViewPager中使用自定义日历视图,所以当按下“展开/折叠”按钮时,我的日历视图将动画化折叠所有日历周(只有一周除外)

目标是在展开时滑动月(我想这样做),在崩溃时滑动周

下面的calendarView是包含一些事件的ListView,当用户折叠日历时,ListView高度必须更改

问题是当我试图在ViewPager中折叠calendarView时,他并没有改变高度

calendarView是带有子视图的线性布局,当它不在ViewPager中时,它会设置动画并更改大小

我正在使用小片段将ViewPager高度设置为它

@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.EXACTLY);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@覆盖
测量时的保护空隙(内部宽度测量等级、内部高度测量等级){
整数高度=0;
对于(int i=0;i高度)高度=h;
}
heightMeasureSpec=MeasureSpec.MakeMasureSpec(高度,精确测量);
超级测量(宽度测量、高度测量);
}
我试图覆盖calendarView上的onMeasure,使用了不同的动画,试图直接更改ViewPager布局,但没有成功

请帮我解决这个问题,也许有个小提示

我发现,还有更多的问题


我的问题非常类似于问题

,所以最后我找到了解决问题的方法,也许会有帮助

这是我的PagerAdapter:

class CustomAdapter extends PagerAdapter {

    private View mCurrentView;

    ...

    // Saving current active item
    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        mCurrentView = (View) object;
    }

     public View getCurrentItem() {
        return mCurrentView;
    }

}
这是我的ViewPager课程

class CustomViewPager extends ViewPager {

    private CustomViewPagerAdapter mAdapter;

    ...

    // Set ViewPager height to currentItem
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int height = 0;
        View v = mAdapter.getCurrentItem();
        if(v != null) {
            v.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            height = v.getMeasuredHeight();
        }

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

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

使用此功能,我可以折叠/展开ViewPager childs,它将正确测量其高度,并测量页面更改时的延迟时间。

非常感谢,您的解决方案确实有所帮助。对其进行了一些修改,以便与FragmentPagerAdpter一起使用。嘿,伙计,我想尝试一下你的解决方案,但我想知道如何使用你的适配器,谢谢你一如既往地使用你的寻呼机适配器,只需添加我上面提供的代码。@MonicaM你能分享一下你是如何使用FragmentPagerAdpter的吗?@John61590我跳过了这些代码,您必须自己初始化它。