List of usage examples for android.view View getMeasuredHeight
public final int getMeasuredHeight()
From source file:cn.ieclipse.af.view.ScrollLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (debug) {// w ww . j a va 2s . c o m Log.v(TAG, String.format("onLayout changed=%b,l=%d,t=%d,r=%d,b=%d", changed, l, t, r, b)); } if (changed) { int childLeft = 0; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View childView = getChildAt(i); if (childView.getVisibility() != View.GONE) { final int childWidth = childView.getMeasuredWidth(); childView.layout(childLeft, 0, childLeft + childWidth, childView.getMeasuredHeight()); childLeft += childWidth; } } } }
From source file:com.cqyw.goheadlines.widget.horizonListView.HorizontalListView.java
private void positionItems(final int dx) { if (getChildCount() > 0) { mDisplayOffset += dx;//ww w. ja v a 2 s. c om int left = mDisplayOffset; for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); int childWidth = child.getMeasuredWidth(); child.layout(left, 0, left + childWidth, child.getMeasuredHeight()); left += childWidth + child.getPaddingRight(); } } }
From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java
@NonNull @Override// w w w . ja va 2 s.c o m public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); LayoutInflater inflater = this.getActivity().getLayoutInflater(); final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null); final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(), getActivity().getString(R.string.icon_font)); ((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface); builder.setView(dialog_view); builder.setCancelable(false); dialog = builder.create(); final Bundle bundle = getArguments(); ArrayList<Bus> buses = null; if (bundle != null) { buses = bundle.getParcelableArrayList(NotificationState.BUSES); } if (buses != null && !buses.isEmpty()) { dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE); setBusMap(buses); ArrayList<String> serviceList = new ArrayList<>(); serviceList.addAll(this.busMap.keySet()); BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap, new BusSelectionAdapter.ListViewAdapterListener() { @Override public void onPositiveClick(Bus bus) { dialog.cancel(); listener.onPositiveClick(bus); } @Override public void onNegativeClick() { dialog.cancel(); listener.onNegativeClick(); } }); ListView listView = (ListView) dialog_view.findViewById(R.id.list_view); listView.setAdapter(adapter); if (adapter.getCount() > VISIBLE_BUSES) { View item = adapter.getView(0, null, listView); item.measure(0, 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight())); listView.setLayoutParams(params); } } Button otherAcceptButton = (Button) dialog_view.findViewById(R.id.accept); otherAcceptButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText serviceEditText = (EditText) dialog_view.findViewById(R.id.service_edit_text); EditText licensePlateEditText = (EditText) dialog_view.findViewById(R.id.license_plate_edit_text); String service = serviceEditText.getText().toString(); String licensePlate = licensePlateEditText.getText().toString(); ServiceHelper helper = new ServiceHelper(getContext()); if (ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0) { service = Util.formatServiceName(service); if (licensePlate.equals("")) { licensePlate = Constants.DUMMY_LICENSE_PLATE; } else if (!LicensePlateValidator.validate(licensePlate)) { Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT) .show(); return; } } else { Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show(); return; } final Bus bus = new Bus(Util.formatServiceName(service), licensePlate); InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); Log.d("BusSelectionDialog", "hiding soft input"); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { BusSelectionDialog.this.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.cancel(); listener.onPositiveClick(bus); } }); } }, 500); //dialog.cancel(); // TODO(aantoine): This call is to quick, some times the keyboard is not // out of the window when de sliding panel shows up. //listener.onPositiveClick(bus); } }); /* set cancel button to close dialog */ dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); listener.onNegativeClick(); } }); ((Button) dialog_view.findViewById(R.id.close_dialog)).setTypeface(iconTypeface); dialog.setCanceledOnTouchOutside(false); return dialog; }
From source file:angeloid.dreamnarae.SwipeyTabs.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (mAdapter == null) { return;/*from w ww. ja v a 2s . c o m*/ } final int count = mAdapter.getCount(); for (int i = 0; i < count; i++) { View v = getChildAt(i); v.layout(mCurrentTabPos[i], this.getPaddingTop(), mCurrentTabPos[i] + v.getMeasuredWidth(), this.getPaddingTop() + v.getMeasuredHeight()); } }
From source file:com.chess.genesis.view.SwipeTabs.java
@Override protected void onLayout(final boolean changed, final int l, final int t, final int r, final int b) { if (mAdapter == null) return;//from w w w .j av a 2 s .co m final int count = mAdapter.getCount(); for (int i = 0; i < count; i++) { final View v = getChildAt(i); v.layout(mCurrentTabPos[i], this.getPaddingTop(), mCurrentTabPos[i] + v.getMeasuredWidth(), this.getPaddingTop() + v.getMeasuredHeight()); } }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java
protected void setPopupKeyboardWithView(int x, int y, int originX, int originY, View contentView) { mMiniKeyboardOriginX = originX;// ww w. j a v a2s . com mMiniKeyboardOriginY = originY; mMiniKeyboardPopup.setContentView(contentView); CompatUtils.setPopupUnattachedToDecor(mMiniKeyboardPopup); mMiniKeyboardPopup.setWidth(contentView.getMeasuredWidth()); mMiniKeyboardPopup.setHeight(contentView.getMeasuredHeight()); mMiniKeyboardPopup.showAtLocation(this, Gravity.NO_GRAVITY, x, y); invalidateAllKeys(); }
From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_width=\"match_parent\" (or fill_parent)"); }/*from www . j a v a2s . com*/ final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode == MeasureSpec.UNSPECIFIED) { throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_height=\"wrap_content\""); } final int contentWidth = MeasureSpec.getSize(widthMeasureSpec); int maxHeight = mContentHeight > 0 ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec); final int verticalPadding = getPaddingTop() + getPaddingBottom(); int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight(); final int height = maxHeight - verticalPadding; final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); if (mClose != null) { availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0); MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams(); availableWidth -= lp.leftMargin + lp.rightMargin; } if (mMenuView != null && mMenuView.getParent() == this) { availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0); } if (mTitleLayout != null && mCustomView == null) { availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0); } if (mCustomView != null) { ViewGroup.LayoutParams lp = mCustomView.getLayoutParams(); final int customWidthMode = lp.width != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; final int customWidth = lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth; final int customHeightMode = lp.height != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; final int customHeight = lp.height >= 0 ? Math.min(lp.height, height) : height; mCustomView.measure(MeasureSpec.makeMeasureSpec(customWidth, customWidthMode), MeasureSpec.makeMeasureSpec(customHeight, customHeightMode)); } if (mContentHeight <= 0) { int measuredHeight = 0; final int count = getChildCount(); for (int i = 0; i < count; i++) { View v = getChildAt(i); int paddedViewHeight = v.getMeasuredHeight() + verticalPadding; if (paddedViewHeight > measuredHeight) { measuredHeight = paddedViewHeight; } } setMeasuredDimension(contentWidth, measuredHeight); } else { setMeasuredDimension(contentWidth, maxHeight); } }
From source file:android.support.v7.internal.widget.ActionBarContextView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_width=\"match_parent\" (or fill_parent)"); }/* w ww. j av a 2s . c om*/ final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode == MeasureSpec.UNSPECIFIED) { throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_height=\"wrap_content\""); } final int contentWidth = MeasureSpec.getSize(widthMeasureSpec); int maxHeight = mContentHeight > 0 ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec); final int verticalPadding = getPaddingTop() + getPaddingBottom(); int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight(); final int height = maxHeight - verticalPadding; final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); if (mClose != null) { availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0); MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams(); availableWidth -= lp.leftMargin + lp.rightMargin; } if (mMenuView != null && mMenuView.getParent() == this) { availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0); } if (mTitleLayout != null && mCustomView == null) { if (mTitleOptional) { final int titleWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); mTitleLayout.measure(titleWidthSpec, childSpecHeight); final int titleWidth = mTitleLayout.getMeasuredWidth(); final boolean titleFits = titleWidth <= availableWidth; if (titleFits) { availableWidth -= titleWidth; } mTitleLayout.setVisibility(titleFits ? VISIBLE : GONE); } else { availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0); } } if (mCustomView != null) { ViewGroup.LayoutParams lp = mCustomView.getLayoutParams(); final int customWidthMode = lp.width != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; final int customWidth = lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth; final int customHeightMode = lp.height != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; final int customHeight = lp.height >= 0 ? Math.min(lp.height, height) : height; mCustomView.measure(MeasureSpec.makeMeasureSpec(customWidth, customWidthMode), MeasureSpec.makeMeasureSpec(customHeight, customHeightMode)); } if (mContentHeight <= 0) { int measuredHeight = 0; final int count = getChildCount(); for (int i = 0; i < count; i++) { View v = getChildAt(i); int paddedViewHeight = v.getMeasuredHeight() + verticalPadding; if (paddedViewHeight > measuredHeight) { measuredHeight = paddedViewHeight; } } setMeasuredDimension(contentWidth, measuredHeight); } else { setMeasuredDimension(contentWidth, maxHeight); } }
From source file:am.widget.tabstrip.HorizontalLinearTabStripLayout.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthSize = MeasureSpec.getSize(widthMeasureSpec); final int paddingStart = ViewCompat.getPaddingStart(this); final int paddingEnd = ViewCompat.getPaddingEnd(this); final int paddingTop = getPaddingTop(); final int paddingBottom = getPaddingBottom(); final int suggestedMinimumHeight = getSuggestedMinimumHeight(); if (getChildCount() <= 0) { setMeasuredDimension(widthSize,/*from ww w .j a v a2 s .com*/ resolveSize(Math.max(paddingTop + paddingBottom, suggestedMinimumHeight), heightMeasureSpec)); return; } final int count = getChildCount(); int contentWidth; if (count % 2 == 0 && mCenter != null) { // contentWidth = widthSize - paddingStart - paddingEnd - mCenter.getIntrinsicWidth(); if (isShowingDividers()) { final int divider = mDivider.getIntrinsicWidth(); if ((mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING) contentWidth -= divider; if ((mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END) contentWidth -= divider; if ((mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE) { contentWidth -= divider * (count - 2); if (mCenterAsItem) contentWidth = contentWidth - divider - divider; } } } else { // contentWidth = widthSize - paddingStart - paddingEnd; if (isShowingDividers()) { final int divider = mDivider.getIntrinsicWidth(); if ((mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING) contentWidth -= divider; if ((mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END) contentWidth -= divider; if ((mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE) contentWidth -= divider * (count - 1); } } final int childWidth = Math.max(0, contentWidth) / count; final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY); final int size = Math.max(0, MeasureSpec.getSize(heightMeasureSpec) - paddingTop - paddingBottom); int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.getMode(heightMeasureSpec)); int childHeight = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); if (childHeight == 0) { childHeight = child.getMeasuredHeight(); childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY); } } setMeasuredDimension(widthSize, resolveSize( Math.max(childHeight + paddingTop + paddingBottom, suggestedMinimumHeight), heightMeasureSpec)); mChildWidth = childWidth; mChildHeight = childHeight; }
From source file:com.bamalearn.bamalearnburmese.DrawerMainActivity.java
public void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return;/*from ww w . j a v a2s. co m*/ } int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom(); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); if (listItem instanceof ViewGroup) listItem.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT, AbsListView.LayoutParams.WRAP_CONTENT)); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); }