List of usage examples for android.view View getVisibility
@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), @ViewDebug.IntToString(from = GONE, to = "GONE") }) @Visibility public int getVisibility()
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // Children are just made to fill our space. mChildWidthMeasureSpec = MeasureSpec .makeMeasureSpec(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec .makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true;//w w w . j a v a 2 s. c o m populate(); mInLayout = false; // Make sure all children have been properly measured. final int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) { Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); } child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } } }
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java
/** * We only want the current page that is being shown to be focusable. *///from w ww. ja va2 s.c o m @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from w w w . ja v a 2s . co m*/ populate(); mInLayout = false; final int count = getChildCount(); final int width = r - l; for (int i = 0; i < count; i++) { View child = getChildAt(i); ItemInfo ii; if (child.getVisibility() != GONE && (ii = infoForChild(child)) != null) { int loff = (width + mPageMargin) * ii.position; int childLeft = getPaddingLeft() + loff; int childTop = getPaddingTop(); if (DEBUG) { Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight()); } child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } mFirstLayout = false; }
From source file:android.support.v7.widget.LinearLayoutCompat.java
private void forceUniformWidth(int count, int heightMeasureSpec) { // Pretend that the linear layout has an exact size. int uniformMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY); for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child.getVisibility() != GONE) { LinearLayoutCompat.LayoutParams lp = ((LinearLayoutCompat.LayoutParams) child.getLayoutParams()); if (lp.width == LayoutParams.MATCH_PARENT) { // Temporarily force children to reuse their old measured height // FIXME: this may not be right for something like wrapping text? int oldHeight = lp.height; lp.height = child.getMeasuredHeight(); // Remeasue with new dimensions measureChildWithMargins(child, uniformMeasureSpec, 0, heightMeasureSpec, 0); lp.height = oldHeight;// w w w. j av a2s . c o m } } } }
From source file:android.support.v7.widget.LinearLayoutCompat.java
private void forceUniformHeight(int count, int widthMeasureSpec) { // Pretend that the linear layout has an exact size. This is the measured height of // ourselves. The measured height should be the max height of the children, changed // to accommodate the heightMeasureSpec from the parent int uniformMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY); for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child.getVisibility() != GONE) { LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams(); if (lp.height == LayoutParams.MATCH_PARENT) { // Temporarily force children to reuse their old measured width // FIXME: this may not be right for something like wrapping text? int oldWidth = lp.width; lp.width = child.getMeasuredWidth(); // Remeasure with new dimensions measureChildWithMargins(child, widthMeasureSpec, 0, uniformMeasureSpec, 0); lp.width = oldWidth;/* www .j av a 2 s. c o m*/ } } } }
From source file:android.support.v7.widget.LinearLayoutCompat.java
void drawDividersVertical(Canvas canvas) { final int count = getVirtualChildCount(); for (int i = 0; i < count; i++) { final View child = getVirtualChildAt(i); if (child != null && child.getVisibility() != GONE) { if (hasDividerBeforeChildAt(i)) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int top = child.getTop() - lp.topMargin - mDividerHeight; drawHorizontalDivider(canvas, top); }//from w w w.jav a2 s .co m } } if (hasDividerBeforeChildAt(count)) { final View child = getVirtualChildAt(count - 1); int bottom = 0; if (child == null) { bottom = getHeight() - getPaddingBottom() - mDividerHeight; } else { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); bottom = child.getBottom() + lp.bottomMargin; } drawHorizontalDivider(canvas, bottom); } }
From source file:com.bm.wjsj.View.LazyViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // Children are just made to fill our space. mChildWidthMeasureSpec = MeasureSpec .makeMeasureSpec(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec .makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true;/*from w ww . ja v a 2 s . c om*/ populate(); mInLayout = false; // Make sure all children have been properly measured. final int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } } }
From source file:android.support.v7.widget.LinearLayoutCompat.java
void drawDividersHorizontal(Canvas canvas) { final int count = getVirtualChildCount(); final boolean isLayoutRtl = ViewUtils.isLayoutRtl(this); for (int i = 0; i < count; i++) { final View child = getVirtualChildAt(i); if (child != null && child.getVisibility() != GONE) { if (hasDividerBeforeChildAt(i)) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int position; if (isLayoutRtl) { position = child.getRight() + lp.rightMargin; } else { position = child.getLeft() - lp.leftMargin - mDividerWidth; }//from w ww.j a v a 2s.c om drawVerticalDivider(canvas, position); } } } if (hasDividerBeforeChildAt(count)) { final View child = getVirtualChildAt(count - 1); int position; if (child == null) { if (isLayoutRtl) { position = getPaddingLeft(); } else { position = getWidth() - getPaddingRight() - mDividerWidth; } } else { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isLayoutRtl) { position = child.getLeft() - lp.leftMargin - mDividerWidth; } else { position = child.getRight() + lp.rightMargin; } } drawVerticalDivider(canvas, position); } }
From source file:com.android.calendar.event.EditEventView.java
private void addFieldsRecursive(StringBuilder b, View v) { if (v == null || v.getVisibility() != View.VISIBLE) { return;/*from w ww. j a va 2 s. co m*/ } if (v instanceof TextView) { CharSequence tv = ((TextView) v).getText(); if (!TextUtils.isEmpty(tv.toString().trim())) { b.append(tv + PERIOD_SPACE); } } else if (v instanceof RadioGroup) { RadioGroup rg = (RadioGroup) v; int id = rg.getCheckedRadioButtonId(); if (id != View.NO_ID) { b.append(((RadioButton) (v.findViewById(id))).getText() + PERIOD_SPACE); } } else if (v instanceof Spinner) { Spinner s = (Spinner) v; if (s.getSelectedItem() instanceof String) { String str = ((String) (s.getSelectedItem())).trim(); if (!TextUtils.isEmpty(str)) { b.append(str + PERIOD_SPACE); } } } else if (v instanceof ViewGroup) { ViewGroup vg = (ViewGroup) v; int children = vg.getChildCount(); for (int i = 0; i < children; i++) { addFieldsRecursive(b, vg.getChildAt(i)); } } }
From source file:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout.java
@Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { if (this.isInEditMode()) { // Don't crash the layout editor. Consume all of the space if // specified // or pick a magic number from thin air otherwise. // TODO Better communication with tools of this bogus state. // It will crash on a real device. if (widthMode == MeasureSpec.AT_MOST) { widthMode = MeasureSpec.EXACTLY; } else if (widthMode == MeasureSpec.UNSPECIFIED) { widthMode = MeasureSpec.EXACTLY; widthSize = 300;/*from ww w .ja va2s. c o m*/ } } else { throw new IllegalStateException("Width must have an exact value or MATCH_PARENT"); } } else if (heightMode == MeasureSpec.UNSPECIFIED) { if (this.isInEditMode()) { // Don't crash the layout editor. Pick a magic number from thin // air instead. // TODO Better communication with tools of this bogus state. // It will crash on a real device. if (heightMode == MeasureSpec.UNSPECIFIED) { heightMode = MeasureSpec.AT_MOST; heightSize = 300; } } else { throw new IllegalStateException("Height must not be UNSPECIFIED"); } } int layoutHeight = 0; int maxLayoutHeight = -1; switch (heightMode) { case MeasureSpec.EXACTLY: layoutHeight = maxLayoutHeight = heightSize - this.getPaddingTop() - this.getPaddingBottom(); break; case MeasureSpec.AT_MOST: maxLayoutHeight = heightSize - this.getPaddingTop() - this.getPaddingBottom(); break; } float weightSum = 0; boolean canSlide = false; int widthRemaining = widthSize - this.getPaddingLeft() - this.getPaddingRight(); final int childCount = this.getChildCount(); if (childCount > 2) { Log.e(HSlidingPaneLayout.TAG, "onMeasure: More than two child views are not supported."); } // We'll find the current one below. this.mSlideableView = null; // First pass. Measure based on child LayoutParams width/height. // Weight will incur a second pass. for (int i = 0; i < childCount; i++) { final View child = this.getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getVisibility() == View.GONE) { lp.dimWhenOffset = false; continue; } if (lp.weight > 0) { weightSum += lp.weight; // If we have no width, weight is the only contributor to the // final size. // Measure this view on the weight pass only. if (lp.width == 0) { continue; } } int childWidthSpec; final int horizontalMargin = lp.leftMargin + lp.rightMargin; if (lp.width == android.view.ViewGroup.LayoutParams.WRAP_CONTENT) { childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - horizontalMargin, MeasureSpec.AT_MOST); } else if (lp.width == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - horizontalMargin, MeasureSpec.EXACTLY); } else { childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY); } int childHeightSpec; if (lp.height == android.view.ViewGroup.LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST); } else if (lp.height == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } child.measure(childWidthSpec, childHeightSpec); final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); if ((heightMode == MeasureSpec.AT_MOST) && (childHeight > layoutHeight)) { layoutHeight = Math.min(childHeight, maxLayoutHeight); } widthRemaining -= childWidth; canSlide |= lp.slideable = widthRemaining < 0; if (lp.slideable) { this.mSlideableView = child; } } if (!isCanSlider) canSlide = false; // Resolve weight and make sure non-sliding panels are smaller than the // full screen. if (canSlide || (weightSum > 0)) { final int fixedPanelWidthLimit = widthSize - this.mOverhangSize; for (int i = 0; i < childCount; i++) { final View child = this.getChildAt(i); if (child.getVisibility() == View.GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getVisibility() == View.GONE) { continue; } final boolean skippedFirstPass = (lp.width == 0) && (lp.weight > 0); final int measuredWidth = skippedFirstPass ? 0 : child.getMeasuredWidth(); if (canSlide && (child != this.mSlideableView)) { if ((lp.width < 0) && ((measuredWidth > fixedPanelWidthLimit) || (lp.weight > 0))) { // Fixed panels in a sliding configuration should // be clamped to the fixed panel limit. final int childHeightSpec; if (skippedFirstPass) { // Do initial height measurement if we skipped // measuring this view // the first time around. if (lp.height == android.view.ViewGroup.LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST); } else if (lp.height == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } } else { childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(), MeasureSpec.EXACTLY); } final int childWidthSpec = MeasureSpec.makeMeasureSpec(fixedPanelWidthLimit, MeasureSpec.EXACTLY); child.measure(childWidthSpec, childHeightSpec); } } else if (lp.weight > 0) { int childHeightSpec; if (lp.width == 0) { // This was skipped the first time; figure out a real // height spec. if (lp.height == android.view.ViewGroup.LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST); } else if (lp.height == android.view.ViewGroup.LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } } else { childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(), MeasureSpec.EXACTLY); } if (canSlide) { // Consume available space final int horizontalMargin = lp.leftMargin + lp.rightMargin; final int newWidth = widthSize - horizontalMargin; final int childWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY); if (measuredWidth != newWidth) { child.measure(childWidthSpec, childHeightSpec); } } else { // Distribute the extra width proportionally similar to // LinearLayout final int widthToDistribute = Math.max(0, widthRemaining); final int addedWidth = (int) ((lp.weight * widthToDistribute) / weightSum); final int childWidthSpec = MeasureSpec.makeMeasureSpec(measuredWidth + addedWidth, MeasureSpec.EXACTLY); child.measure(childWidthSpec, childHeightSpec); } } } } this.setMeasuredDimension(widthSize, layoutHeight); this.mCanSlide = canSlide; if ((this.mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) && !canSlide) { // Cancel scrolling in progress, it's no longer relevant. this.mDragHelper.abort(); } }