码迷,mamicode.com
首页 > 其他好文 > 详细

如何解决在scrollview中的viewpager高度自适应的

时间:2016-04-20 14:56:56      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:

时间:2016年3月18日16:47:56

  1. /**
  2. * 自动适应高度的ViewPager
  3. * @author
  4. *
  5. */
  6. public class CustomViewPager extends ViewPager {
  7. public CustomViewPager(Context context) {
  8. super(context);
  9. }
  10. public CustomViewPager(Context context, AttributeSet attrs) {
  11. super(context, attrs);
  12. }
  13. @Override
  14. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  15. int height = 0;
  16. for (int i = 0; i < getChildCount(); i++) {
  17. View child = getChildAt(i);
  18. child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
  19. int h = child.getMeasuredHeight();
  20. if (h > height)
  21. height = h;
  22. }
  23. heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
  24. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  25. }
  26. }





如何解决在scrollview中的viewpager高度自适应的

标签:

原文地址:http://www.cnblogs.com/yuzhongzheng/p/5412577.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!