当前位置: 首页 > news >正文

中山制作企业网站优化流程

中山制作企业网站,优化流程,wordpress怎么连接数据库配置文件,利用ionic做的网站当我们在使用到ScrollView和ListView的时候可能会出现显示不全的问题。那我们可以进行以下分析 ScrollView在测量子布局的时候会用UNSPECIFIED。通过源码观察#xff0c; 在ScrollView的onMeasure方法中 Overrideprotected void onMeasure(int widthMeasureSpec, int heightMe…当我们在使用到ScrollView和ListView的时候可能会出现显示不全的问题。那我们可以进行以下分析 ScrollView在测量子布局的时候会用UNSPECIFIED。通过源码观察 在ScrollView的onMeasure方法中 Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);if (!mFillViewport) {return;}final int heightMode MeasureSpec.getMode(heightMeasureSpec);if (heightMode MeasureSpec.UNSPECIFIED) {return;}if (getChildCount() 0) {final View child getChildAt(0);final int widthPadding;final int heightPadding;final int targetSdkVersion getContext().getApplicationInfo().targetSdkVersion;final FrameLayout.LayoutParams lp (LayoutParams) child.getLayoutParams();if (targetSdkVersion VERSION_CODES.M) {widthPadding mPaddingLeft mPaddingRight lp.leftMargin lp.rightMargin;heightPadding mPaddingTop mPaddingBottom lp.topMargin lp.bottomMargin;} else {widthPadding mPaddingLeft mPaddingRight;heightPadding mPaddingTop mPaddingBottom;}final int desiredHeight getMeasuredHeight() - heightPadding;if (child.getMeasuredHeight() desiredHeight) {final int childWidthMeasureSpec getChildMeasureSpec(widthMeasureSpec, widthPadding, lp.width);final int childHeightMeasureSpec MeasureSpec.makeMeasureSpec(desiredHeight, MeasureSpec.EXACTLY);child.measure(childWidthMeasureSpec, childHeightMeasureSpec);}}} 点击super.onMeasure()方法可以观察到进入了FrameLayout中 Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int count getChildCount();final boolean measureMatchParentChildren MeasureSpec.getMode(widthMeasureSpec) ! MeasureSpec.EXACTLY ||MeasureSpec.getMode(heightMeasureSpec) ! MeasureSpec.EXACTLY;mMatchParentChildren.clear();int maxHeight 0;int maxWidth 0;int childState 0;for (int i 0; i count; i) {final View child getChildAt(i);if (mMeasureAllChildren || child.getVisibility() ! GONE) {measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);final LayoutParams lp (LayoutParams) child.getLayoutParams();maxWidth Math.max(maxWidth,child.getMeasuredWidth() lp.leftMargin lp.rightMargin);maxHeight Math.max(maxHeight,child.getMeasuredHeight() lp.topMargin lp.bottomMargin);childState combineMeasuredStates(childState, child.getMeasuredState());if (measureMatchParentChildren) {if (lp.width LayoutParams.MATCH_PARENT ||lp.height LayoutParams.MATCH_PARENT) {mMatchParentChildren.add(child);}}}}// Account for padding toomaxWidth getPaddingLeftWithForeground() getPaddingRightWithForeground();maxHeight getPaddingTopWithForeground() getPaddingBottomWithForeground();// Check against our minimum height and widthmaxHeight Math.max(maxHeight, getSuggestedMinimumHeight());maxWidth Math.max(maxWidth, getSuggestedMinimumWidth());// Check against our foregrounds minimum height and widthfinal Drawable drawable getForeground();if (drawable ! null) {maxHeight Math.max(maxHeight, drawable.getMinimumHeight());maxWidth Math.max(maxWidth, drawable.getMinimumWidth());}setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),resolveSizeAndState(maxHeight, heightMeasureSpec,childState MEASURED_HEIGHT_STATE_SHIFT));count mMatchParentChildren.size();if (count 1) {for (int i 0; i count; i) {final View child mMatchParentChildren.get(i);final MarginLayoutParams lp (MarginLayoutParams) child.getLayoutParams();final int childWidthMeasureSpec;if (lp.width LayoutParams.MATCH_PARENT) {final int width Math.max(0, getMeasuredWidth()- getPaddingLeftWithForeground() - getPaddingRightWithForeground()- lp.leftMargin - lp.rightMargin);childWidthMeasureSpec MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);} else {childWidthMeasureSpec getChildMeasureSpec(widthMeasureSpec,getPaddingLeftWithForeground() getPaddingRightWithForeground() lp.leftMargin lp.rightMargin,lp.width);}final int childHeightMeasureSpec;if (lp.height LayoutParams.MATCH_PARENT) {final int height Math.max(0, getMeasuredHeight()- getPaddingTopWithForeground() - getPaddingBottomWithForeground()- lp.topMargin - lp.bottomMargin);childHeightMeasureSpec MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);} else {childHeightMeasureSpec getChildMeasureSpec(heightMeasureSpec,getPaddingTopWithForeground() getPaddingBottomWithForeground() lp.topMargin lp.bottomMargin,lp.height);}child.measure(childWidthMeasureSpec, childHeightMeasureSpec);}}}里面有个measureChildWithMargins方法 protected void measureChildWithMargins(View child,int parentWidthMeasureSpec, int widthUsed,int parentHeightMeasureSpec, int heightUsed) {final MarginLayoutParams lp (MarginLayoutParams) child.getLayoutParams();final int childWidthMeasureSpec getChildMeasureSpec(parentWidthMeasureSpec,mPaddingLeft mPaddingRight lp.leftMargin lp.rightMargin widthUsed, lp.width);final int childHeightMeasureSpec getChildMeasureSpec(parentHeightMeasureSpec,mPaddingTop mPaddingBottom lp.topMargin lp.bottomMargin heightUsed, lp.height);child.measure(childWidthMeasureSpec, childHeightMeasureSpec);}这个时候发现ScrollView有重写这个方法 Overrideprotected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed,int parentHeightMeasureSpec, int heightUsed) {final MarginLayoutParams lp (MarginLayoutParams) child.getLayoutParams();final int childWidthMeasureSpec getChildMeasureSpec(parentWidthMeasureSpec,mPaddingLeft mPaddingRight lp.leftMargin lp.rightMargin widthUsed, lp.width);final int usedTotal mPaddingTop mPaddingBottom lp.topMargin lp.bottomMargin heightUsed;final int childHeightMeasureSpec MeasureSpec.makeSafeMeasureSpec(Math.max(0, MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal),MeasureSpec.UNSPECIFIED);child.measure(childWidthMeasureSpec, childHeightMeasureSpec);}其中childHeightMeasureSpec的模式是MeasureSpec.UNSPECIFIED。这个表示尽可能的大很少能用到。 而我们的ListView也会调用onMeaure方法 Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// Sets up mListPaddingsuper.onMeasure(widthMeasureSpec, heightMeasureSpec);final int widthMode MeasureSpec.getMode(widthMeasureSpec);final int heightMode MeasureSpec.getMode(heightMeasureSpec);int widthSize MeasureSpec.getSize(widthMeasureSpec);int heightSize MeasureSpec.getSize(heightMeasureSpec);int childWidth 0;int childHeight 0;int childState 0;mItemCount mAdapter null ? 0 : mAdapter.getCount();if (mItemCount 0 (widthMode MeasureSpec.UNSPECIFIED|| heightMode MeasureSpec.UNSPECIFIED)) {final View child obtainView(0, mIsScrap);// Lay out child directly against the parent measure spec so that// we can obtain exected minimum width and height.measureScrapChild(child, 0, widthMeasureSpec, heightSize);childWidth child.getMeasuredWidth();childHeight child.getMeasuredHeight();childState combineMeasuredStates(childState, child.getMeasuredState());if (recycleOnMeasure() mRecycler.shouldRecycleViewType(((LayoutParams) child.getLayoutParams()).viewType)) {mRecycler.addScrapView(child, 0);}}if (widthMode MeasureSpec.UNSPECIFIED) {widthSize mListPadding.left mListPadding.right childWidth getVerticalScrollbarWidth();} else {widthSize | (childState MEASURED_STATE_MASK);}if (heightMode MeasureSpec.UNSPECIFIED) {heightSize mListPadding.top mListPadding.bottom childHeight getVerticalFadingEdgeLength() * 2;}if (heightMode MeasureSpec.AT_MOST) {// TODO: after first layout we should maybe start at the first visible position, not 0heightSize measureHeightOfChildren(widthMeasureSpec, 0, NO_POSITION, heightSize, -1);}setMeasuredDimension(widthSize, heightSize);mWidthMeasureSpec widthMeasureSpec;}其中的heightMeasureSpec也就是我们在ScrollView中child.measure(childWidthMeasureSpec, childHeightMeasureSpec);在传递过来的。所以也是模式为MeasureSpec.UNSPECIFIED。而当heightMode MeasureSpec.UNSPECIFIED时会调用 if (heightMode MeasureSpec.UNSPECIFIED) {heightSize mListPadding.top mListPadding.bottom childHeight getVerticalFadingEdgeLength() * 2;}这样在heightSize mListPadding.top mListPadding.bottom childHeight getVerticalFadingEdgeLength() * 2只是加了一个childHeight 所以展示的只有一个item的大小。 所以要解决这个问题应该让listView进入heightMode MeasureSpec.AT_MOST里。 public class MyListView extends ListView {public MyListView(Context context) {super(context);}public MyListView(Context context, AttributeSet attrs) {super(context, attrs);}public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {//解决显示不全的问题heightMeasureSpecMeasureSpec.makeMeasureSpec(Integer.MAX_VALUE2,MeasureSpec.AT_MOST);super.onMeasure(widthMeasureSpec, heightMeasureSpec);} } 网上有的博客换成MyListView这么做就实现了那么为什么呢 首先当我们的模式为AT_MOST if (heightMode MeasureSpec.AT_MOST) {// TODO: after first layout we should maybe start at the first visible position, not 0heightSize measureHeightOfChildren(widthMeasureSpec, 0, NO_POSITION, heightSize, -1);}调用ListView的measureHeightOfChildren UnsupportedAppUsage(maxTargetSdk Build.VERSION_CODES.P, trackingBug 115609023)final int measureHeightOfChildren(int widthMeasureSpec, int startPosition, int endPosition,int maxHeight, int disallowPartialChildPosition) {final ListAdapter adapter mAdapter;if (adapter null) {return mListPadding.top mListPadding.bottom;}// Include the padding of the listint returnedHeight mListPadding.top mListPadding.bottom;final int dividerHeight mDividerHeight;// The previous height value that was less than maxHeight and contained// no partial childrenint prevHeightWithoutPartialChild 0;int i;View child;// mItemCount - 1 since endPosition parameter is inclusiveendPosition (endPosition NO_POSITION) ? adapter.getCount() - 1 : endPosition;final AbsListView.RecycleBin recycleBin mRecycler;final boolean recyle recycleOnMeasure();final boolean[] isScrap mIsScrap;for (i startPosition; i endPosition; i) {child obtainView(i, isScrap);measureScrapChild(child, i, widthMeasureSpec, maxHeight);if (i 0) {// Count the divider for all but one childreturnedHeight dividerHeight;}// Recycle the view before we possibly return from the methodif (recyle recycleBin.shouldRecycleViewType(((LayoutParams) child.getLayoutParams()).viewType)) {recycleBin.addScrapView(child, -1);}returnedHeight child.getMeasuredHeight();if (returnedHeight maxHeight) {// We went over, figure out which height to return. If returnedHeight maxHeight,// then the ith position did not fit completely.return (disallowPartialChildPosition 0) // Disallowing is enabled ( -1) (i disallowPartialChildPosition) // Weve past the min pos (prevHeightWithoutPartialChild 0) // We have a prev height (returnedHeight ! maxHeight) // ith child did not fit completely? prevHeightWithoutPartialChild: maxHeight;}if ((disallowPartialChildPosition 0) (i disallowPartialChildPosition)) {prevHeightWithoutPartialChild returnedHeight;}}// At this point, we went through the range of children, and they each// completely fit, so return the returnedHeightreturn returnedHeight;}因为returnedHeight一直在累加这样我们让maxHeight为最大值这样他就不会进入if (returnedHeight maxHeight) 而是返回returnedHeight。 onMeasure方法中的widthMeasureSpec和heightMeasureSpec会包含两个信息第一个信息是模式2位第二个信息是值30位。一共32位 而这里为什么Integer.MAX_VALUE 要右移两位 public static int makeMeasureSpec(IntRange(from 0, to (1 MeasureSpec.MODE_SHIFT) - 1) int size,MeasureSpecMode int mode) {if (sUseBrokenMakeMeasureSpec) {return size mode;} else {return (size ~MODE_MASK) | (mode MODE_MASK);}}因为Integer.MAX_VALUE右移两位等于一个30位的值这样执行makeMeasureSpec就可以构建成一个32位的值。这样去替换ListView的heightMeasureSpec即可。 /*** A constant holding the maximum value an {code int} can* have, 2sup31/sup-1.*/Native public static final int MAX_VALUE 0x7fffffff;
http://www.pierceye.com/news/526561/

相关文章:

  • 殡仪馆做网站的好处制作响应式网站报价
  • 网站建设平台杭州做网站前台后台是怎么连接的
  • 太原市0元网站建设wordpress wcps
  • 怎么自己做免费网站wordpress 优酷通用代码自适应
  • 网站设置三方交易深圳品牌设计公司招聘
  • 东莞响应式网站哪家好网站开发应用到的技术名词
  • 背景做网站公司docker wordpress
  • 吉林建设监理协会网站网站 服务器 虚拟主机
  • 食品公司网站设计项目和男朋友都是第一次做网站
  • wordpress the7.6搜索引擎优化工作原理的先后顺序
  • 淘宝不允许 网站建设微网站如何做宣传
  • 海西高端网站建设价格怎样开通微信小商店
  • 学校校园网站建设方案南宁有做门户网站的公司吗
  • 一般电商都是在哪些网站上做wordpress 获取所有子页面
  • 长沙岳麓区网站开发网址大全首页
  • 学网站建设难不难专业网页美工招聘
  • 网站制作的公司有哪些四川成都有什么好玩的
  • 网站做wanzhihou专门做课件的网站
  • 如何做app网站中国建筑第八工程局有限公司
  • 网站设计素材网站cpa个人网站怎么做
  • 做徽标的网站做软件去哪个网站
  • 网站初始开发的步骤自己做的网站有排名吗
  • 山东建设厅官方网站一级建造师有什么网站可以做代理的
  • 哪个网站公司做的好百科网站推广
  • 网站首页做很多个关键词做羊水亲子鉴定网站
  • 漳州 做网站东昌府区住房和城乡建设局网站
  • 网站前台首页无法显示济南市网站
  • c2c网站开发毕业设计东莞网站营销公司
  • 网站维护企业wordpress数字分页
  • 怎么判断一个网站做的好不好discuz 企业网站